Module: wine Branch: master Commit: f65c426776d91765130c2ebcda2c65140d56cb8c URL: https://source.winehq.org/git/wine.git/?a=commit;h=f65c426776d91765130c2ebcd...
Author: Piotr Caban piotr@codeweavers.com Date: Mon Oct 28 13:28:54 2019 +0100
ucrtbase: Implement %G format for strftime.
Signed-off-by: Piotr Caban piotr@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/msvcrt/time.c | 9 +++++++++ dlls/ucrtbase/tests/misc.c | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index 588f724cf7..8f4d64b361 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1196,6 +1196,15 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f if(!strftime_int(str, &ret, max, mstm->tm_mday, alternate ? 0 : 2, 0, 31)) return 0; break; + case 'G': + tmp = 1900 + mstm->tm_year; + if (mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4 < 0) + tmp--; + else if(mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 5 > 365 + IsLeapYear(tmp)) + tmp++; + if (!strftime_int(str, &ret, max, tmp, 4, 0, 9999)) + return 0; + break; #endif case 'H': if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23)) diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index da2e7d34ca..9cfe532560 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -138,6 +138,7 @@ static void (CDECL *p___setusermatherr)(MSVCRT_matherr_func); static int* (CDECL *p_errno)(void); static char* (CDECL *p_asctime)(const struct tm *); static size_t (__cdecl *p_strftime)(char *, size_t, const char *, const struct tm *); +static struct tm* (__cdecl *p__gmtime32)(const __time32_t*); static void (CDECL *p_exit)(int); static int (CDECL *p__crt_atexit)(void (CDECL*)(void)); static int (__cdecl *p_crt_at_quick_exit)(void (__cdecl *func)(void)); @@ -509,6 +510,7 @@ static BOOL init(void) p_errno = (void*)GetProcAddress(module, "_errno"); p_asctime = (void*)GetProcAddress(module, "asctime"); p_strftime = (void*)GetProcAddress(module, "strftime"); + p__gmtime32 = (void*)GetProcAddress(module, "_gmtime32"); p__crt_atexit = (void*)GetProcAddress(module, "_crt_atexit"); p_exit = (void*)GetProcAddress(module, "exit"); p_crt_at_quick_exit = (void*)GetProcAddress(module, "_crt_at_quick_exit"); @@ -904,6 +906,7 @@ static void test_strftime(void) const struct tm tm1 = { 0, 0, 0, 1, 0, 117, 0, 0, 0 }; char bufA[256]; size_t retA; + int i;
retA = p_strftime(bufA, sizeof(bufA), "%C", &epoch); ok(retA == 2, "expected 2, got %d\n", (int)retA); @@ -964,6 +967,27 @@ static void test_strftime(void) retA = p_strftime(bufA, sizeof(bufA), "%t", &epoch); ok(retA == 1, "expected 1, got %d\n", (int)retA); ok(!strcmp(bufA, "\t"), "got %s\n", bufA); + + retA = p_strftime(bufA, sizeof(bufA), "%G", &epoch); + ok(retA == 4, "expected 4, got %d\n", (int)retA); + ok(!strcmp(bufA, "1970"), "got %s\n", bufA); + + retA = p_strftime(bufA, sizeof(bufA), "%G", &tm1); + ok(retA == 4, "expected 4, got %d\n", (int)retA); + ok(!strcmp(bufA, "2016"), "got %s\n", bufA); + + for(i=0; i<14; i++) + { + __time32_t t = (365*2 + i - 7) * 24 * 60 * 60; + struct tm tm = *p__gmtime32(&t); + + retA = p_strftime(bufA, sizeof(bufA), "%G", &tm); + ok(retA == 4, "%d) retA = %d\n", i, (int)retA); + if (i <= 8) + ok(!strcmp(bufA, "1971"), "%d) got %s, expected 1971\n", i, bufA); + else + ok(!strcmp(bufA, "1972"), "%d) got %s, expected 1972\n", i, bufA); + } }
static LONG* get_failures_counter(HANDLE *map)