Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/time.c | 26 ++++++++++++++++++++++++++ dlls/ucrtbase/tests/misc.c | 6 ++++++ 2 files changed, 32 insertions(+)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index 9787d18e3f..3f378b0d1a 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1033,6 +1033,26 @@ static inline BOOL strftime_time(char *str, MSVCRT_size_t *pos, MSVCRT_size_t ma return TRUE; }
+static inline BOOL strftime_tzdiff(char *str, MSVCRT_size_t *pos, MSVCRT_size_t max, int dst) +{ + MSVCRT_size_t len; + MSVCRT_long tz = MSVCRT___timezone + (dst * MSVCRT__dstbias); + + char sign = (tz > 0) ? '-' : '+'; + unsigned int minutes = ((tz < 0) ? -tz : tz) / 60; + unsigned int hours = minutes / 60; + + len = MSVCRT__snprintf(str+*pos, max-*pos, "%c%02u%02u", sign, hours, minutes % 60); + if(*pos + len > max) { + *str = 0; + *MSVCRT__errno() = MSVCRT_ERANGE; + return FALSE; + } + + *pos += len; + return TRUE; +} + static inline BOOL strftime_str(char *str, MSVCRT_size_t *pos, MSVCRT_size_t max, char *src) { MSVCRT_size_t len = strlen(src); @@ -1300,6 +1320,12 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f return 0; break; case 'z': +#if _MSVCR_VER>=140 + MSVCRT__tzset(); + if(!strftime_tzdiff(str, &ret, max, mstm->tm_isdst ? 1 : 0)) + return 0; + break; +#endif case 'Z': MSVCRT__tzset(); if(MSVCRT__get_tzname(&tmp, str+ret, max-ret, mstm->tm_isdst ? 1 : 0)) diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index 3a1598fee2..014d66d595 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -1005,6 +1005,12 @@ static void test_strftime(void) todo_wine ok(retA == 2, "expected 2, got %d\n", (int)retA); todo_wine ok(!strcmp(bufA, "53"), "got %s\n", bufA);
+ retA = p_strftime(bufA, sizeof(bufA), "%z", &tm2); + ok(retA == 5, "expected 5, got %d\n", (int)retA); + ok((bufA[0] == '+' || bufA[0] == '-') && + isdigit(bufA[1]) && isdigit(bufA[2]) && + isdigit(bufA[3]) && isdigit(bufA[4]), "got %s\n", bufA); + for(i=0; i<14; i++) { __time32_t t = (365*2 + i - 7) * 24 * 60 * 60;
Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/time.c | 9 ++++++++- dlls/ucrtbase/tests/misc.c | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index 3f378b0d1a..e2d1424a59 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -1311,7 +1311,14 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f return 0; break; case 'y': - if(!strftime_int(str, &ret, max, mstm->tm_year%100, alternate ? 0 : 2, 0, 99)) +#if _MSVCR_VER>=140 + if (mstm->tm_year < -1900 || mstm->tm_year > 8099) + goto einval_error; + tmp = (mstm->tm_year+1900)%100; +#else + tmp = mstm->tm_year%100; +#endif + if(!strftime_int(str, &ret, max, tmp, alternate ? 0 : 2, 0, 99)) return 0; break; case 'Y': diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index 014d66d595..5252b9d963 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -902,9 +902,19 @@ static void test_asctime(void)
static void test_strftime(void) { + const struct { + int in; + const char *out; + } years[] = { + {-1901, ""}, + {-1900, "00"}, + {8099, "99"}, + {8100, ""}, + }; const struct tm epoch = { 0, 0, 0, 1, 0, 70, 4, 0, 0 }; const struct tm tm1 = { 0, 0, 0, 1, 0, 117, 0, 0, 0 }; const struct tm tm2 = { 0, 0, 14, 1, 0, 121, 6, 0, 0 }; + struct tm tm3 = { 0, 0, 14, 1, 0, 0, 6, 0, 0 }; char bufA[256]; size_t retA; int i; @@ -1011,6 +1021,15 @@ static void test_strftime(void) isdigit(bufA[1]) && isdigit(bufA[2]) && isdigit(bufA[3]) && isdigit(bufA[4]), "got %s\n", bufA);
+ for(i = 0; i < ARRAY_SIZE(years); i++) { + tm3.tm_year = years[i].in; + retA = p_strftime(bufA, sizeof(bufA), "%y", &tm3); + ok(retA == strlen(years[i].out), "for %d, expected %d, got %d\n", + years[i].in, strlen(years[i].out), (int)retA); + ok(!strcmp(bufA, years[i].out), "for %d, expected '%s', got '%s'\n", + years[i].in, years[i].out, bufA); + } + for(i=0; i<14; i++) { __time32_t t = (365*2 + i - 7) * 24 * 60 * 60;