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

ucrtbase: Treat year more consistently in strftime.

parent 4152f944
...@@ -1190,6 +1190,7 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, ...@@ -1190,6 +1190,7 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
{ {
MSVCRT_size_t ret, tmp; MSVCRT_size_t ret, tmp;
BOOL alternate; BOOL alternate;
int year = mstm ? mstm->tm_year + 1900 : -1;
if(!str || !format) { if(!str || !format) {
if(str && max) if(str && max)
...@@ -1272,8 +1273,9 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, ...@@ -1272,8 +1273,9 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
break; break;
#if _MSVCR_VER>=140 #if _MSVCR_VER>=140
case 'C': case 'C':
tmp = (1900+mstm->tm_year)/100; if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 2, 0, 99)) goto einval_error;
if(!strftime_int(str, &ret, max, year/100, alternate ? 0 : 2, 0, 99))
return 0; return 0;
break; break;
#endif #endif
...@@ -1283,6 +1285,8 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, ...@@ -1283,6 +1285,8 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
break; break;
#if _MSVCR_VER>=140 #if _MSVCR_VER>=140
case 'D': case 'D':
if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
goto einval_error;
if(!strftime_int(str, &ret, max, mstm->tm_mon+1, alternate ? 0 : 2, 1, 12)) if(!strftime_int(str, &ret, max, mstm->tm_mon+1, alternate ? 0 : 2, 1, 12))
return 0; return 0;
if(ret < max) if(ret < max)
...@@ -1291,7 +1295,7 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, ...@@ -1291,7 +1295,7 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
return 0; return 0;
if(ret < max) if(ret < max)
str[ret++] = '/'; str[ret++] = '/';
if(!strftime_int(str, &ret, max, mstm->tm_year%100, alternate ? 0 : 2, 0, 99)) if(!strftime_int(str, &ret, max, year%100, alternate ? 0 : 2, 0, 99))
return 0; return 0;
break; break;
case 'e': case 'e':
...@@ -1301,8 +1305,7 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, ...@@ -1301,8 +1305,7 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
str[ret-2] = ' '; str[ret-2] = ' ';
break; break;
case 'F': case 'F':
tmp = 1900+mstm->tm_year; if(!strftime_int(str, &ret, max, year, alternate ? 0 : 4, 0, 9999))
if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 4, 0, 9999))
return 0; return 0;
if(ret < max) if(ret < max)
str[ret++] = '-'; str[ret++] = '-';
...@@ -1315,7 +1318,7 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, ...@@ -1315,7 +1318,7 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
break; break;
case 'g': case 'g':
case 'G': case 'G':
tmp = 1900 + mstm->tm_year; tmp = year;
if (mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4 < 0) if (mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4 < 0)
tmp--; tmp--;
else if(mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 5 > 365 + IsLeapYear(tmp)) else if(mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 5 > 365 + IsLeapYear(tmp))
...@@ -1409,18 +1412,16 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, ...@@ -1409,18 +1412,16 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
break; break;
case 'y': case 'y':
#if _MSVCR_VER>=140 #if _MSVCR_VER>=140
if(!MSVCRT_CHECK_PMT(mstm->tm_year>=-1900 && mstm->tm_year<=8099)) if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
goto einval_error;
tmp = (mstm->tm_year+1900)%100;
#else #else
tmp = mstm->tm_year%100; if(!MSVCRT_CHECK_PMT(year>=1900))
#endif #endif
if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 2, 0, 99)) goto einval_error;
if(!strftime_int(str, &ret, max, year%100, alternate ? 0 : 2, 0, 99))
return 0; return 0;
break; break;
case 'Y': case 'Y':
tmp = 1900+mstm->tm_year; if(!strftime_int(str, &ret, max, year, alternate ? 0 : 4, 0, 9999))
if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 4, 0, 9999))
return 0; return 0;
break; break;
case 'z': case 'z':
......
...@@ -930,23 +930,23 @@ static void test_strftime(void) ...@@ -930,23 +930,23 @@ static void test_strftime(void)
BOOL todo; BOOL todo;
BOOL todo_handler; BOOL todo_handler;
} tests[] = { } tests[] = {
{"%C", "", { 0, 0, 0, 1, 0, -2000, 4, 0, 0 }, FALSE, TRUE}, {"%C", "", { 0, 0, 0, 1, 0, -2000, 4, 0, 0 }},
{"%C", "", { 0, 0, 0, 1, 0, -1901, 4, 0, 0 }, TRUE}, {"%C", "", { 0, 0, 0, 1, 0, -1901, 4, 0, 0 }},
{"%C", "00", { 0, 0, 0, 1, 0, -1900, 4, 0, 0 }}, {"%C", "00", { 0, 0, 0, 1, 0, -1900, 4, 0, 0 }},
{"%C", "18", { 0, 0, 0, 1, 0, -1, 4, 0, 0 }}, {"%C", "18", { 0, 0, 0, 1, 0, -1, 4, 0, 0 }},
{"%C", "19", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, {"%C", "19", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }},
{"%C", "99", { 0, 0, 0, 1, 0, 8099, 4, 0, 0 }}, {"%C", "99", { 0, 0, 0, 1, 0, 8099, 4, 0, 0 }},
{"%C", "", { 0, 0, 0, 1, 0, 8100, 4, 0, 0 }, FALSE, TRUE}, {"%C", "", { 0, 0, 0, 1, 0, 8100, 4, 0, 0 }},
{"%d", "", { 0, 0, 0, 0, 0, 70, 4, 0, 0 }, TRUE}, {"%d", "", { 0, 0, 0, 0, 0, 70, 4, 0, 0 }, TRUE},
{"%d", "01", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, {"%d", "01", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }},
{"%d", "31", { 0, 0, 0, 31, 0, 70, 4, 0, 0 }}, {"%d", "31", { 0, 0, 0, 31, 0, 70, 4, 0, 0 }},
{"%d", "", { 0, 0, 0, 32, 0, 70, 4, 0, 0 }, FALSE, TRUE}, {"%d", "", { 0, 0, 0, 32, 0, 70, 4, 0, 0 }, FALSE, TRUE},
{"%D", "", { 0, 0, 0, 1, 0, -1901, 4, 0, 0 }, FALSE, TRUE}, {"%D", "", { 0, 0, 0, 1, 0, -1901, 4, 0, 0 }},
{"%D", "01/01/00", { 0, 0, 0, 1, 0, -1900, 4, 0, 0 }}, {"%D", "01/01/00", { 0, 0, 0, 1, 0, -1900, 4, 0, 0 }},
{"%D", "01/01/99", { 0, 0, 0, 1, 0, -1, 4, 0, 0 }, TRUE}, {"%D", "01/01/99", { 0, 0, 0, 1, 0, -1, 4, 0, 0 }},
{"%D", "01/01/70", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, {"%D", "01/01/70", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }},
{"%D", "01/01/99", { 0, 0, 0, 1, 0, 8099, 4, 0, 0 }}, {"%D", "01/01/99", { 0, 0, 0, 1, 0, 8099, 4, 0, 0 }},
{"%D", "", { 0, 0, 0, 1, 0, 8100, 4, 0, 0 }, TRUE}, {"%D", "", { 0, 0, 0, 1, 0, 8100, 4, 0, 0 }},
{"%#D", "1/1/70", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, {"%#D", "1/1/70", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }},
{"%e", "", { 0, 0, 0, 0, 0, 70, 4, 0, 0 }, TRUE}, {"%e", "", { 0, 0, 0, 0, 0, 70, 4, 0, 0 }, TRUE},
{"%e", " 1", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, {"%e", " 1", { 0, 0, 0, 1, 0, 70, 4, 0, 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