From c6bafaa6d92b78c82be5b955cae455f581750a00 Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Thu, 28 Nov 2019 01:57:42 -0600 Subject: [PATCH] ucrtbase: Add support for strftime format %r. Signed-off-by: Jeff Smith Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- 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 42835661024..ef4f2285548 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1386,6 +1386,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 c1ab7f216a7..083be42f427 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 {