[PATCH 5/5] ucrtbase: Correct behavior of strftime format %c.
Jeff Smith
whydoubt at gmail.com
Sun Nov 17 22:27:40 CST 2019
Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---
dlls/msvcrt/time.c | 33 ++++++++++++++++++++++++---------
dlls/ucrtbase/tests/misc.c | 4 ++--
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c
index c601bb0fbc..ae9e819438 100644
--- a/dlls/msvcrt/time.c
+++ b/dlls/msvcrt/time.c
@@ -1135,8 +1135,9 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f
{
MSVCRT_size_t ret, tmp;
BOOL alternate;
+ MSVCRT_pthreadlocinfo locinfo;
- TRACE("(%p %ld %s %p %p)\n", str, max, format, mstm, time_data);
+ TRACE("(%p %ld %s %p %p %p)\n", str, max, format, mstm, time_data, loc);
if(!str || !format) {
if(str && max)
@@ -1145,8 +1146,9 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f
return 0;
}
+ locinfo = loc ? loc->locinfo : get_locinfo();
if(!time_data)
- time_data = loc ? loc->locinfo->lc_time_curr : get_locinfo()->lc_time_curr;
+ time_data = locinfo->lc_time_curr;
for(ret=0; *format && ret<max; format++) {
if(*format != '%') {
@@ -1173,13 +1175,26 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f
switch(*format) {
case 'c':
- if(!strftime_format(str, &ret, max, mstm, time_data,
- alternate ? time_data->str.names.date : time_data->str.names.short_date))
- return 0;
- if(ret < max)
- str[ret++] = ' ';
- if(!strftime_format(str, &ret, max, mstm, time_data, time_data->str.names.time))
- return 0;
+#if _MSVCR_VER>=140
+ if (!strcmp(locinfo->lc_category[MSVCRT_LC_TIME].locale, "C") && !alternate)
+ {
+ MSVCRT_size_t day_offset = ret + 8;
+ if(!strftime_format(str, &ret, max, mstm, time_data, "ddd MMM dd HH:mm:ss yyyy"))
+ return 0;
+ if(str[day_offset] == '0')
+ str[day_offset] = ' ';
+ }
+ else
+#endif
+ {
+ if(!strftime_format(str, &ret, max, mstm, time_data,
+ alternate ? time_data->str.names.date : time_data->str.names.short_date))
+ return 0;
+ if(ret < max)
+ str[ret++] = ' ';
+ if(!strftime_format(str, &ret, max, mstm, time_data, time_data->str.names.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 3aca31734f..e4170faef3 100644
--- a/dlls/ucrtbase/tests/misc.c
+++ b/dlls/ucrtbase/tests/misc.c
@@ -936,8 +936,8 @@ static void test_strftime(void)
{"%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 }},
+ {"%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 }},
--
2.23.0
More information about the wine-devel
mailing list