[PATCH 3/4] ucrtbase: Add support for strftime format %V.
Jeff Smith
whydoubt at gmail.com
Tue Nov 26 00:00:49 CST 2019
Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---
dlls/msvcrt/time.c | 13 ++++++++-
dlls/ucrtbase/tests/misc.c | 57 ++++++++++++++++++++++++++++++++++++--
2 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c
index 50e571540f..eea47ec2cd 100644
--- a/dlls/msvcrt/time.c
+++ b/dlls/msvcrt/time.c
@@ -1196,7 +1196,7 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
MSVCRT_size_t ret, tmp;
BOOL alternate;
#if _MSVCR_VER>=140
- int tmp_year;
+ int tmp_year, tmp_days;
#endif
int year = mstm ? mstm->tm_year + 1900 : -1;
@@ -1342,6 +1342,17 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
return 0;
}
break;
+ case 'V':
+ tmp_year = year;
+ tmp_days = mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4;
+ if (tmp_days < 0)
+ tmp_days += 365 + IsLeapYear(--tmp_year);
+ else if(tmp_days >= 365 + IsLeapYear(tmp_year))
+ tmp_days -= 365 + IsLeapYear(tmp_year++);
+
+ if(!strftime_int(str, &ret, max, tmp_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))
diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c
index a33742e9c1..de1c0f1288 100644
--- a/dlls/ucrtbase/tests/misc.c
+++ b/dlls/ucrtbase/tests/misc.c
@@ -994,9 +994,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},
- {"%V", "52", { 0, 0, 0, 1, 0, 117, 0, 0, 0 }, TRUE},
- {"%V", "53", { 0, 0, 14, 1, 0, 121, 6, 0, 0 }, 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 }},
@@ -1081,6 +1081,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" },
@@ -1095,6 +1131,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;
@@ -1137,6 +1174,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)
--
2.23.0
More information about the wine-devel
mailing list