Commit cdcbb9f3 authored by Jeff Smith's avatar Jeff Smith Committed by Alexandre Julliard

ucrtbase: Use correct type for year with strftime format %g.

parent d0319e20
......@@ -1325,20 +1325,24 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
break;
case 'g':
case 'G':
tmp = year;
{
int iso_year = year;
if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
goto einval_error;
if (mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4 < 0)
tmp--;
else if(mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 5 > 365 + IsLeapYear(tmp))
tmp++;
iso_year--;
else if(mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 5 > 365 + IsLeapYear(iso_year))
iso_year++;
if(*format == 'G')
{
if (!strftime_int(str, &ret, max, tmp, 4, 0, 9999))
if (!strftime_int(str, &ret, max, iso_year, 4, 0, 9999))
return 0;
} else {
if (!strftime_int(str, &ret, max, tmp%100, 2, 0, 99))
if (!strftime_int(str, &ret, max, iso_year%100, 2, 0, 99))
return 0;
}
break;
}
#endif
case 'H':
if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23))
......
......@@ -977,8 +977,8 @@ static void test_strftime(void)
{"%r", "12:00:00 AM", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }, TRUE, TRUE},
{"%r", "02:00:00 PM", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }, TRUE, TRUE},
{"%t", "\t", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }},
{"%g", "", { 0, 0, 0, 1, 0, -1901, 4, 0, 0 }, TRUE},
{"%g", "", { 0, 0, 0, 1, 0, -1901, 3, 364, 0 }, TRUE, TRUE},
{"%g", "", { 0, 0, 0, 1, 0, -1901, 4, 0, 0 }},
{"%g", "", { 0, 0, 0, 1, 0, -1901, 3, 364, 0 }},
{"%g", "00", { 0, 0, 0, 1, 0, -1900, 4, 0, 0 }},
{"%g", "70", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }},
{"%g", "71", { 0, 0, 0, 2, 0, 72, 0, 1, 0 }},
......@@ -986,8 +986,8 @@ static void test_strftime(void)
{"%g", "16", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }},
{"%g", "99", { 0, 0, 0, 1, 0, 8099, 4, 0, 0 }},
{"%g", "00", { 0, 0, 0, 1, 0, 8099, 3, 364, 0 }},
{"%g", "", { 0, 0, 0, 1, 0, 8100, 0, 0, 0 }, TRUE, TRUE},
{"%g", "", { 0, 0, 0, 1, 0, 8100, 4, 0, 0 }, TRUE, TRUE},
{"%g", "", { 0, 0, 0, 1, 0, 8100, 0, 0, 0 }},
{"%g", "", { 0, 0, 0, 1, 0, 8100, 4, 0, 0 }},
{"%G", "1970", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }},
{"%G", "1971", { 0, 0, 0, 2, 0, 72, 0, 1, 0 }},
{"%G", "1972", { 0, 0, 0, 3, 0, 72, 1, 2, 0 }},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment