ucrtbase: Implement %g format for strftime.

Signed-off-by: Vijay Kiran Kamuju <infyquest@gmail.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Vijay Kiran Kamuju 2019-10-29 14:43:52 +01:00 committed by Alexandre Julliard
parent 32088c0c09
commit 54f4bfb06d
2 changed files with 24 additions and 2 deletions

View File

@ -1196,14 +1196,21 @@ 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':
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;
if(*format == 'G')
{
if (!strftime_int(str, &ret, max, tmp, 4, 0, 9999))
return 0;
} else {
if (!strftime_int(str, &ret, max, tmp%100, 2, 0, 99))
return 0;
}
break;
#endif
case 'H':

View File

@ -968,6 +968,14 @@ static void test_strftime(void)
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 == 2, "expected 2, got %d\n", (int)retA);
ok(!strcmp(bufA, "70"), "got %s\n", bufA);
retA = p_strftime(bufA, sizeof(bufA), "%g", &tm1);
ok(retA == 2, "expected 2, got %d\n", (int)retA);
ok(!strcmp(bufA, "16"), "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);
@ -981,6 +989,13 @@ static void test_strftime(void)
__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 == 2, "%d) retA = %d\n", i, (int)retA);
if (i <= 8)
ok(!strcmp(bufA, "71"), "%d) got %s, expected 71\n", i, bufA);
else
ok(!strcmp(bufA, "72"), "%d) got %s, expected 72\n", i, bufA);
retA = p_strftime(bufA, sizeof(bufA), "%G", &tm);
ok(retA == 4, "%d) retA = %d\n", i, (int)retA);
if (i <= 8)