From 420f5edfe7676fe6e7cddbbf15c04649d096e422 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 13 Oct 2015 13:27:30 +0100 Subject: win32: fix implementation of '%z' in strftime Windows' strftime prints the name of the timezone rather than the timezone offset for '%z'. Add a hack to do it properly. Windows' strftime also uses its own version of the timezone name for '%Z'. A workaround for this is to set the TZ environment variable. --- win32/mingw.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/win32/mingw.c b/win32/mingw.c index 876b74221..211c378a3 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -862,6 +862,33 @@ size_t mingw_strftime(char *buf, size_t max, const char *format, const struct tm t = newfmt + m + 1; fmt = newfmt; } + else if ( t[1] == 'z' ) { + char buffer[16] = ""; + + *t = '\0'; + m = t - fmt; + _tzset(); + if ( tm->tm_isdst >= 0 ) { + int offset = (int)_timezone - (tm->tm_isdst > 0 ? 3600 : 0); + int hr, min; + + if ( offset > 0 ) { + buffer[0] = '-'; + } + else { + buffer[0] = '+'; + offset = -offset; + } + + hr = offset / 3600; + min = (offset % 3600) / 60; + sprintf(buffer+1, "%02d%02d", hr, min); + } + newfmt = xasprintf("%s%s%s", fmt, buffer, t+2); + free(fmt); + t = newfmt + m + 1; + fmt = newfmt; + } else if ( t[1] != '\0' ) { ++t; } -- cgit v1.2.3-55-g6feb