From 20810377ed6353cc59c4b73149f132178657de80 Mon Sep 17 00:00:00 2001 From: Vijay Kiran Kamuju Date: Mon, 30 Sep 2019 16:52:14 +0200 Subject: [PATCH] msvcrt: Implement %R format for strftime. Signed-off-by: Vijay Kiran Kamuju Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcrt/tests/time.c | 5 +++++ dlls/msvcrt/time.c | 10 ++++++++++ dlls/ucrtbase/tests/misc.c | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/dlls/msvcrt/tests/time.c b/dlls/msvcrt/tests/time.c index fea7ca19db4..faf1a6dcb46 100644 --- a/dlls/msvcrt/tests/time.c +++ b/dlls/msvcrt/tests/time.c @@ -608,6 +608,11 @@ static void test_strftime(void) gmt_tm = p_gmtime(&gmt); ok(gmt_tm != NULL, "gmtime failed\n"); + errno = 0xdeadbeef; + retA = p_strftime(bufA, 256, "%R", gmt_tm); + ok(retA == 0, "expected 0, got %ld\n", retA); + ok(errno==EINVAL || broken(errno==0xdeadbeef), "errno = %d\n", errno); + errno = 0xdeadbeef; retA = p_strftime(bufA, 256, "%T", gmt_tm); ok(retA == 0, "expected 0, got %ld\n", retA); diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index 4aaa89ac0e9..c72b3ed21ee 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1189,6 +1189,16 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f time_data->str.names.am : time_data->str.names.pm)) return 0; break; +#if _MSVCR_VER>=140 + case 'R': + if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23)) + return 0; + if(ret < max) + str[ret++] = ':'; + if(!strftime_int(str, &ret, max, mstm->tm_min, alternate ? 0 : 2, 0, 59)) + return 0; + break; +#endif case 'S': if(!strftime_int(str, &ret, max, mstm->tm_sec, alternate ? 0 : 2, 0, 59)) return 0; diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index bb0c2e3a0a2..02ea1297bb2 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -895,6 +895,14 @@ static void test_strftime(void) char bufA[256]; size_t retA; + retA = p_strftime(bufA, sizeof(bufA), "%R", &epoch); + ok(retA == 5, "expected 5, got %d\n", (int)retA); + ok(!strcmp(bufA, "00:00"), "got %s\n", bufA); + + retA = p_strftime(bufA, sizeof(bufA), "%#R", &epoch); + ok(retA == 3, "expected 3, got %d\n", (int)retA); + ok(!strcmp(bufA, "0:0"), "got %s\n", bufA); + retA = p_strftime(bufA, sizeof(bufA), "%T", &epoch); ok(retA == 8, "expected 8, got %d\n", (int)retA); ok(!strcmp(bufA, "00:00:00"), "got %s\n", bufA);