From 0b78dd17aed035b430ce6e9b5a0087f4dcb38ee7 Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Wed, 4 Dec 2019 15:30:57 +0100 Subject: [PATCH] ucrtbase: Correct behavior of strftime formats %c %r. Signed-off-by: Jeff Smith Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcrt/time.c | 14 +++++++++++++- dlls/ucrtbase/tests/misc.c | 8 ++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index ef4f2285548..7f565e350d8 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1234,6 +1234,18 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, switch(*format) { case 'c': +#if _MSVCR_VER>=140 + if(time_data == &cloc_time_data && !alternate) + { + static const WCHAR datetime_format[] = + { '%','a',' ','%','b',' ','%','e',' ','%','T',' ','%','Y',0 }; + tmp = strftime_impl(str+ret, max-ret, datetime_format, mstm, time_data, loc); + if(!tmp) + return 0; + ret += tmp; + break; + } +#endif if(!strftime_format(str, &ret, max, mstm, time_data, alternate ? STRFTIME_TD(time_data, date) : STRFTIME_TD(time_data, short_date))) return 0; @@ -1387,7 +1399,7 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, break; #if _MSVCR_VER>=140 case 'r': - if(time_data == MSVCRT_locale->locinfo->lc_time_curr) + if(time_data == &cloc_time_data) { if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23)) goto einval_error; diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index a3a20aa9b16..f637997a0d1 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -1004,8 +1004,8 @@ static void test_strftime(void) {"%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 }}, - {"%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", "Thu Jan 1 00:00:00 1970", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, + {"%c", "Thu Feb 30 00:00:00 1970", { 0, 0, 0, 30, 1, 70, 4, 0, 0 }}, {"%#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 }}, @@ -1197,8 +1197,8 @@ static void test_strftime(void) ok(ret == 19, "ret = %d\n", ret); ok(!strcmp(buf, "01/01/1970 00:00:00"), "buf = \"%s\", expected \"%s\"\n", buf, "01/01/1970 00:00:00"); ret = p_strftime(buf, sizeof(buf), "%r", &epoch); - todo_wine ok(ret == 8, "ret = %d\n", ret); - todo_wine ok(!strcmp(buf, "00:00:00"), "buf = \"%s\", expected \"%s\"\n", buf, "00:00:00"); + ok(ret == 8, "ret = %d\n", ret); + ok(!strcmp(buf, "00:00:00"), "buf = \"%s\", expected \"%s\"\n", buf, "00:00:00"); p_setlocale(LC_ALL, "C"); } -- 2.11.4.GIT