ucrtbase: Add support for strftime format %V.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jeff Smith 2019-11-27 17:52:31 +01:00 committed by Alexandre Julliard
parent cdcbb9f369
commit 4f5342fff0
2 changed files with 67 additions and 3 deletions

View File

@ -1343,6 +1343,19 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
}
break;
}
case 'V':
{
int iso_year = year;
int iso_days = mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4;
if (iso_days < 0)
iso_days += 365 + IsLeapYear(--iso_year);
else if(iso_days >= 365 + IsLeapYear(iso_year))
iso_days -= 365 + IsLeapYear(iso_year++);
if(!strftime_int(str, &ret, max, iso_days/7 + 1, alternate ? 0 : 2, 0, 53))
return 0;
break;
}
#endif
case 'H':
if(!strftime_int(str, &ret, max, mstm->tm_hour, alternate ? 0 : 2, 0, 23))

View File

@ -992,9 +992,9 @@ static void test_strftime(void)
{"%G", "1971", { 0, 0, 0, 2, 0, 72, 0, 1, 0 }},
{"%G", "1972", { 0, 0, 0, 3, 0, 72, 1, 2, 0 }},
{"%G", "2016", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }},
{"%V", "01", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }, TRUE, TRUE},
{"%V", "52", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }, TRUE, TRUE},
{"%V", "53", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }, TRUE, TRUE},
{"%V", "01", { 0, 0, 0, 1, 0, 70, 4, 0, 0 }},
{"%V", "52", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }},
{"%V", "53", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }},
{"%y", "", { 0, 0, 0, 0, 0, -1901, 0, 0, 0 }},
{"%y", "00", { 0, 0, 0, 0, 0, -1900, 0, 0, 0 }},
{"%y", "99", { 0, 0, 0, 0, 0, 8099, 0, 0, 0 }},
@ -1079,6 +1079,42 @@ static void test_strftime(void)
{ "%#x", "y1970", 0, L"yyyyy", 0, { 0, 0, 0, 1, 0, 70, 0, 0, 0 }},
};
const struct {
int year;
int yday;
const char *ret[7];
} tests_yweek[] = {
{ 100, 0, { "99 52", "00 01", "00 01", "00 01", "00 01", "99 53", "99 52" }},
{ 100, 1, { "99 52", "00 01", "00 01", "00 01", "00 01", "00 01", "99 53" }},
{ 100, 2, { "99 53", "00 01", "00 01", "00 01", "00 01", "00 01", "00 01" }},
{ 100, 3, { "00 01", "00 01", "00 01", "00 01", "00 01", "00 01", "00 01" }},
{ 100, 4, { "00 01", "00 02", "00 01", "00 01", "00 01", "00 01", "00 01" }},
{ 100, 5, { "00 01", "00 02", "00 02", "00 01", "00 01", "00 01", "00 01" }},
{ 100, 6, { "00 01", "00 02", "00 02", "00 02", "00 01", "00 01", "00 01" }},
{ 100, 358, { "00 51", "00 52", "00 52", "00 52", "00 52", "00 52", "00 51" }},
{ 100, 359, { "00 51", "00 52", "00 52", "00 52", "00 52", "00 52", "00 52" }},
{ 100, 360, { "00 52", "00 52", "00 52", "00 52", "00 52", "00 52", "00 52" }},
{ 100, 361, { "00 52", "00 53", "00 52", "00 52", "00 52", "00 52", "00 52" }},
{ 100, 362, { "00 52", "00 53", "00 53", "00 52", "00 52", "00 52", "00 52" }},
{ 100, 363, { "00 52", "01 01", "00 53", "00 53", "00 52", "00 52", "00 52" }},
{ 100, 364, { "00 52", "01 01", "01 01", "00 53", "00 53", "00 52", "00 52" }},
{ 100, 365, { "00 52", "01 01", "01 01", "01 01", "00 53", "00 53", "00 52" }},
{ 101, 0, { "00 52", "01 01", "01 01", "01 01", "01 01", "00 53", "00 53" }},
{ 101, 1, { "00 53", "01 01", "01 01", "01 01", "01 01", "01 01", "00 53" }},
{ 101, 2, { "00 53", "01 01", "01 01", "01 01", "01 01", "01 01", "01 01" }},
{ 101, 3, { "01 01", "01 01", "01 01", "01 01", "01 01", "01 01", "01 01" }},
{ 101, 4, { "01 01", "01 02", "01 01", "01 01", "01 01", "01 01", "01 01" }},
{ 101, 5, { "01 01", "01 02", "01 02", "01 01", "01 01", "01 01", "01 01" }},
{ 101, 6, { "01 01", "01 02", "01 02", "01 02", "01 01", "01 01", "01 01" }},
{ 101, 358, { "01 51", "01 52", "01 52", "01 52", "01 52", "01 52", "01 51" }},
{ 101, 359, { "01 51", "01 52", "01 52", "01 52", "01 52", "01 52", "01 52" }},
{ 101, 360, { "01 52", "01 52", "01 52", "01 52", "01 52", "01 52", "01 52" }},
{ 101, 361, { "01 52", "01 53", "01 52", "01 52", "01 52", "01 52", "01 52" }},
{ 101, 362, { "01 52", "02 01", "01 53", "01 52", "01 52", "01 52", "01 52" }},
{ 101, 363, { "01 52", "02 01", "02 01", "01 53", "01 52", "01 52", "01 52" }},
{ 101, 364, { "01 52", "02 01", "02 01", "02 01", "01 53", "01 52", "01 52" }},
};
__lc_time_data time_data = {
{ "d1", "d2", "d3", "d4", "d5", "d6", "d7" },
{ "day1", "day2", "day3", "day4", "day5", "day6", "day7" },
@ -1093,6 +1129,7 @@ static void test_strftime(void)
};
const struct tm epoch = { 0, 0, 0, 1, 0, 70, 4, 0, 0 };
struct tm tm_yweek = { 0, 0, 0, 1, 0, 70, 0, 0, 0 };
char buf[256];
int i, ret=0;
@ -1131,6 +1168,20 @@ static void test_strftime(void)
i, buf, tests_td[i].ret);
}
}
for (i=0; i<ARRAY_SIZE(tests_yweek); i++)
{
int j;
tm_yweek.tm_year = tests_yweek[i].year;
tm_yweek.tm_yday = tests_yweek[i].yday;
for (j=0; j<7; j++)
{
tm_yweek.tm_wday = j;
p_strftime(buf, sizeof(buf), "%g %V", &tm_yweek);
ok(!strcmp(buf, tests_yweek[i].ret[j]), "%d,%d) buf = \"%s\", expected \"%s\"\n",
i, j, buf, tests_yweek[i].ret[j]);
}
}
}
static LONG* get_failures_counter(HANDLE *map)