Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/ucrtbase/tests/misc.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index 6314662eac..9b43d73559 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -927,7 +927,7 @@ static void test_strftime(void) const char *format; const char *ret; struct tm tm; - BOOL todo; + BOOL todo_value; BOOL todo_handler; } tests[] = { {"%C", "", { 0, 0, 0, 1, 0, -2000, 4, 0, 0 }}, @@ -974,26 +974,33 @@ static void test_strftime(void) {"%I", "11", { 0, 0, 23, 1, 0, 70, 4, 0, 0 }}, {"%I", "", { 0, 0, 24, 1, 0, 70, 4, 0, 0 }}, {"%n", "\n", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, - {"%r", "12:00:00 AM", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }, TRUE}, - {"%r", "02:00:00 PM", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }, TRUE}, + {"%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", "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 }}, + {"%g", "72", { 0, 0, 0, 3, 0, 72, 1, 2, 0 }}, {"%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", "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 }}, {"%G", "2016", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }}, - {"%V", "01", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }, TRUE}, - {"%V", "52", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }, TRUE}, - {"%V", "53", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }, TRUE}, + {"%V", "01", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }, TRUE, TRUE}, + {"%V", "52", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }, TRUE, TRUE}, + {"%V", "53", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }, TRUE, TRUE}, {"%y", "", { 0, 0, 0, 0, 0, -1901, 0, 0, 0 }}, {"%y", "00", { 0, 0, 0, 0, 0, -1900, 0, 0, 0 }}, {"%y", "99", { 0, 0, 0, 0, 0, 8099, 0, 0, 0 }}, {"%y", "", { 0, 0, 0, 0, 0, 8100, 0, 0, 0 }}, - {"%g", "71", { 0, 0, 0, 2, 0, 72, 0, 1, 0 }}, - {"%g", "72", { 0, 0, 0, 3, 0, 72, 1, 2, 0 }}, - {"%G", "1971", { 0, 0, 0, 2, 0, 72, 0, 1, 0 }}, - {"%G", "1972", { 0, 0, 0, 3, 0, 72, 1, 2, 0 }}, - {"%c", "Thu Jan 1 00:00:00 1970", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }, TRUE}, - {"%c", "Thu Feb 30 00:00:00 1970", { 0, 0, 0, 30, 1, 70, 4, 0, 0 }, TRUE}, + {"%c", "Thu Jan 1 00:00:00 1970", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }, TRUE, TRUE}, + {"%c", "Thu Feb 30 00:00:00 1970", { 0, 0, 0, 30, 1, 70, 4, 0, 0 }, TRUE, TRUE}, {"%#c", "Thursday, January 01, 1970 00:00:00", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, {"%#c", "Thursday, February 30, 1970 00:00:00", { 0, 0, 0, 30, 1, 70, 4, 0, 0 }}, {"%x", "01/01/70", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, @@ -1091,7 +1098,7 @@ static void test_strftime(void)
for (i=0; i<ARRAY_SIZE(tests); i++) { - todo_wine_if(tests[i].todo || tests[i].todo_handler) { + todo_wine_if(tests[i].todo_handler) { if (!tests[i].ret[0]) SET_EXPECT(global_invalid_parameter_handler); ret = p_strftime(buf, sizeof(buf), tests[i].format, &tests[i].tm); @@ -1099,7 +1106,7 @@ static void test_strftime(void) CHECK_CALLED(global_invalid_parameter_handler); }
- todo_wine_if(tests[i].todo) { + todo_wine_if(tests[i].todo_value) { ok(ret == strlen(tests[i].ret), "%d) ret = %d\n", i, ret); ok(!strcmp(buf, tests[i].ret), "%d) buf = "%s", expected "%s"\n", i, buf, tests[i].ret);
Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/time.c | 16 ++++++++++------ dlls/ucrtbase/tests/misc.c | 8 ++++---- 2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index 0d5b64a4aa..3274fe94e6 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1323,19 +1323,23 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, break; case 'g': case 'G': - tmp = year; + if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999)) + goto einval_error; + { + int iso_year = year; 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': diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index 9b43d73559..107bb7e84c 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -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 }},
Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/time.c | 13 +++++++++ dlls/ucrtbase/tests/misc.c | 57 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index 3274fe94e6..a926f7f667 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1341,6 +1341,19 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, } } break; + case 'V': + { + int iso_year = year; + int iso_days = mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4; + if (iso_days < 0) + iso_days += 365 + IsLeapYear(--iso_year); + else if(iso_days >= 365 + IsLeapYear(iso_year)) + iso_days -= 365 + IsLeapYear(iso_year++); + + if(!strftime_int(str, &ret, max, iso_days/7 + 1, alternate ? 0 : 2, 0, 53)) + return 0; + } + break; #endif case 'H': if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23)) diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index 107bb7e84c..c1ab7f216a 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -992,9 +992,9 @@ static void test_strftime(void) {"%G", "1971", { 0, 0, 0, 2, 0, 72, 0, 1, 0 }}, {"%G", "1972", { 0, 0, 0, 3, 0, 72, 1, 2, 0 }}, {"%G", "2016", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }}, - {"%V", "01", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }, TRUE, TRUE}, - {"%V", "52", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }, TRUE, TRUE}, - {"%V", "53", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }, TRUE, TRUE}, + {"%V", "01", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, + {"%V", "52", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }}, + {"%V", "53", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }}, {"%y", "", { 0, 0, 0, 0, 0, -1901, 0, 0, 0 }}, {"%y", "00", { 0, 0, 0, 0, 0, -1900, 0, 0, 0 }}, {"%y", "99", { 0, 0, 0, 0, 0, 8099, 0, 0, 0 }}, @@ -1079,6 +1079,42 @@ static void test_strftime(void) { "%#x", "y1970", 0, L"yyyyy", 0, { 0, 0, 0, 1, 0, 70, 0, 0, 0 }}, };
+ const struct { + int year; + int yday; + const char *ret[7]; + } tests_yweek[] = { + { 100, 0, { "99 52", "00 01", "00 01", "00 01", "00 01", "99 53", "99 52" }}, + { 100, 1, { "99 52", "00 01", "00 01", "00 01", "00 01", "00 01", "99 53" }}, + { 100, 2, { "99 53", "00 01", "00 01", "00 01", "00 01", "00 01", "00 01" }}, + { 100, 3, { "00 01", "00 01", "00 01", "00 01", "00 01", "00 01", "00 01" }}, + { 100, 4, { "00 01", "00 02", "00 01", "00 01", "00 01", "00 01", "00 01" }}, + { 100, 5, { "00 01", "00 02", "00 02", "00 01", "00 01", "00 01", "00 01" }}, + { 100, 6, { "00 01", "00 02", "00 02", "00 02", "00 01", "00 01", "00 01" }}, + { 100, 358, { "00 51", "00 52", "00 52", "00 52", "00 52", "00 52", "00 51" }}, + { 100, 359, { "00 51", "00 52", "00 52", "00 52", "00 52", "00 52", "00 52" }}, + { 100, 360, { "00 52", "00 52", "00 52", "00 52", "00 52", "00 52", "00 52" }}, + { 100, 361, { "00 52", "00 53", "00 52", "00 52", "00 52", "00 52", "00 52" }}, + { 100, 362, { "00 52", "00 53", "00 53", "00 52", "00 52", "00 52", "00 52" }}, + { 100, 363, { "00 52", "01 01", "00 53", "00 53", "00 52", "00 52", "00 52" }}, + { 100, 364, { "00 52", "01 01", "01 01", "00 53", "00 53", "00 52", "00 52" }}, + { 100, 365, { "00 52", "01 01", "01 01", "01 01", "00 53", "00 53", "00 52" }}, + { 101, 0, { "00 52", "01 01", "01 01", "01 01", "01 01", "00 53", "00 53" }}, + { 101, 1, { "00 53", "01 01", "01 01", "01 01", "01 01", "01 01", "00 53" }}, + { 101, 2, { "00 53", "01 01", "01 01", "01 01", "01 01", "01 01", "01 01" }}, + { 101, 3, { "01 01", "01 01", "01 01", "01 01", "01 01", "01 01", "01 01" }}, + { 101, 4, { "01 01", "01 02", "01 01", "01 01", "01 01", "01 01", "01 01" }}, + { 101, 5, { "01 01", "01 02", "01 02", "01 01", "01 01", "01 01", "01 01" }}, + { 101, 6, { "01 01", "01 02", "01 02", "01 02", "01 01", "01 01", "01 01" }}, + { 101, 358, { "01 51", "01 52", "01 52", "01 52", "01 52", "01 52", "01 51" }}, + { 101, 359, { "01 51", "01 52", "01 52", "01 52", "01 52", "01 52", "01 52" }}, + { 101, 360, { "01 52", "01 52", "01 52", "01 52", "01 52", "01 52", "01 52" }}, + { 101, 361, { "01 52", "01 53", "01 52", "01 52", "01 52", "01 52", "01 52" }}, + { 101, 362, { "01 52", "02 01", "01 53", "01 52", "01 52", "01 52", "01 52" }}, + { 101, 363, { "01 52", "02 01", "02 01", "01 53", "01 52", "01 52", "01 52" }}, + { 101, 364, { "01 52", "02 01", "02 01", "02 01", "01 53", "01 52", "01 52" }}, + }; + __lc_time_data time_data = { { "d1", "d2", "d3", "d4", "d5", "d6", "d7" }, { "day1", "day2", "day3", "day4", "day5", "day6", "day7" }, @@ -1093,6 +1129,7 @@ static void test_strftime(void) };
const struct tm epoch = { 0, 0, 0, 1, 0, 70, 4, 0, 0 }; + struct tm tm_yweek = { 0, 0, 0, 1, 0, 70, 0, 0, 0 }; char buf[256]; int i, ret=0;
@@ -1131,6 +1168,20 @@ static void test_strftime(void) i, buf, tests_td[i].ret); } } + + for (i=0; i<ARRAY_SIZE(tests_yweek); i++) + { + int j; + tm_yweek.tm_year = tests_yweek[i].year; + tm_yweek.tm_yday = tests_yweek[i].yday; + for (j=0; j<7; j++) + { + tm_yweek.tm_wday = j; + p_strftime(buf, sizeof(buf), "%g %V", &tm_yweek); + ok(!strcmp(buf, tests_yweek[i].ret[j]), "%d,%d) buf = "%s", expected "%s"\n", + i, j, buf, tests_yweek[i].ret[j]); + } + } }
static LONG* get_failures_counter(HANDLE *map)
Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/time.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index a926f7f667..0d29b1eb51 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1325,22 +1325,6 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, case 'G': if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999)) goto einval_error; - { - int iso_year = year; - if (mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4 < 0) - 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, iso_year, 4, 0, 9999)) - return 0; - } else { - if (!strftime_int(str, &ret, max, iso_year%100, 2, 0, 99)) - return 0; - } - } - break; case 'V': { int iso_year = year; @@ -1350,8 +1334,16 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, else if(iso_days >= 365 + IsLeapYear(iso_year)) iso_days -= 365 + IsLeapYear(iso_year++);
- if(!strftime_int(str, &ret, max, iso_days/7 + 1, alternate ? 0 : 2, 0, 53)) - return 0; + if(*format == 'G') { + if(!strftime_int(str, &ret, max, iso_year, 4, 0, 9999)) + return 0; + } else if(*format == 'g') { + if(!strftime_int(str, &ret, max, iso_year%100, 2, 0, 99)) + return 0; + } else { + if(!strftime_int(str, &ret, max, iso_days/7 + 1, alternate ? 0 : 2, 0, 53)) + return 0; + } } break; #endif