Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/time.c | 28 +++++++++++++++++++++------- dlls/ucrtbase/tests/misc.c | 4 ++-- 2 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index 4283566102..d8043f459d 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1234,13 +1234,27 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
switch(*format) { case 'c': - if(!strftime_format(str, &ret, max, mstm, time_data, - alternate ? STRFTIME_TD(time_data, date) : STRFTIME_TD(time_data, short_date))) - return 0; - if(ret < max) - str[ret++] = ' '; - if(!strftime_format(str, &ret, max, mstm, time_data, STRFTIME_TD(time_data, time))) - return 0; +#if _MSVCR_VER>=140 + if(time_data == MSVCRT_locale->locinfo->lc_time_curr && !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; + } + else +#endif + { + if(!strftime_format(str, &ret, max, mstm, time_data, + alternate ? STRFTIME_TD(time_data, date) : STRFTIME_TD(time_data, short_date))) + return 0; + if(ret < max) + str[ret++] = ' '; + if(!strftime_format(str, &ret, max, mstm, time_data, STRFTIME_TD(time_data, time))) + return 0; + } break; case 'x': if(!strftime_format(str, &ret, max, mstm, time_data, diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index c1ab7f216a..5ff1d1e44e 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -999,8 +999,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 }},
Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/time.c | 28 ++++++++++++++++++++++++++++ dlls/ucrtbase/tests/misc.c | 7 +++++-- 2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index d8043f459d..2cf0ea4ab6 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1400,6 +1400,34 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max, return 0; break; #if _MSVCR_VER>=140 + case 'r': + if(time_data == MSVCRT_locale->locinfo->lc_time_curr) + { + if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23)) + goto einval_error; + if(!strftime_int(str, &ret, max, (mstm->tm_hour + 11) % 12 + 1, + alternate ? 0 : 2, 1, 12)) + return 0; + if(ret < max) + str[ret++] = ':'; + if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59)) + return 0; + if(ret < max) + str[ret++] = ':'; + if(!strftime_int(str, &ret, max, mstm->tm_sec, alternate ? 0 : 2, 0, MAX_SECONDS)) + return 0; + if(ret < max) + str[ret++] = ' '; + if(!strftime_str(str, &ret, max, mstm->tm_hour<12 ? + STRFTIME_TD(time_data, am) : STRFTIME_TD(time_data, pm))) + return 0; + } + else + { + if(!strftime_format(str, &ret, max, mstm, time_data, STRFTIME_TD(time_data, time))) + return 0; + } + break; case 'R': if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23)) return 0; diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index 5ff1d1e44e..48bc8a5f10 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -974,8 +974,10 @@ 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, TRUE}, - {"%r", "02:00:00 PM", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }, TRUE, TRUE}, + {"%r", "12:00:00 AM", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, + {"%r", "02:00:00 PM", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }}, + {"%#r", "12:0:0 AM", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, + {"%#r", "2:0:0 PM", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }}, {"%t", "\t", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }}, {"%g", "", { 0, 0, 0, 1, 0, -1901, 4, 0, 0 }}, {"%g", "", { 0, 0, 0, 1, 0, -1901, 3, 364, 0 }}, @@ -1077,6 +1079,7 @@ static void test_strftime(void) { "%#x", "y70", 0, L"yyy", 0, { 0, 0, 0, 1, 0, 70, 0, 0, 0 }}, { "%#x", "1970", 0, L"yyyy", 0, { 0, 0, 0, 1, 0, 70, 0, 0, 0 }}, { "%#x", "y1970", 0, L"yyyyy", 0, { 0, 0, 0, 1, 0, 70, 0, 0, 0 }}, + { "%r", "z", L"x", L"y", L"z", { 0, 0, 0, 1, 0, 70, 0, 0, 0 }}, };
const struct {
Signed-off-by: Piotr Caban piotr@codeweavers.com
Hi Jeff,
On 11/28/19 8:57 AM, Jeff Smith wrote:
+#if _MSVCR_VER>=140
if(time_data == MSVCRT_locale->locinfo->lc_time_curr && !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;
It's not working as expected when non C locale is used. You can also break inside the if to avoid modifying the other case.
Thanks, Piotr