ucrtbase: Strftime returns 4-digit timezone for %z.

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-13 22:07:42 +01:00 committed by Alexandre Julliard
parent f63138d049
commit d4e2b0584b
2 changed files with 36 additions and 0 deletions

View File

@ -1033,6 +1033,30 @@ 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, BOOL is_dst)
{
MSVCRT_long tz = MSVCRT___timezone + (is_dst ? MSVCRT__dstbias : 0);
MSVCRT_size_t len;
char sign;
if(tz < 0) {
sign = '+';
tz = -tz;
}else {
sign = '-';
}
len = MSVCRT__snprintf(str+*pos, max-*pos, "%c%02u%02u", sign, tz/60/60, tz/60%60);
if(len == -1) {
*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 +1324,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))
return 0;
break;
#endif
case 'Z':
MSVCRT__tzset();
if(MSVCRT__get_tzname(&tmp, str+ret, max-ret, mstm->tm_isdst ? 1 : 0))

View File

@ -1001,6 +1001,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;