Commit f65c4267 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

ucrtbase: Implement %G format for strftime.

parent c18ebdfe
......@@ -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))
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment