diff options
author | Ron Yorston <rmy@pobox.com> | 2015-10-13 13:27:30 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2015-10-13 13:27:30 +0100 |
commit | 420f5edfe7676fe6e7cddbbf15c04649d096e422 (patch) | |
tree | 08afa6acf1844fffaa55aefde4dcd7b583185cf7 | |
parent | 2682149a379ed872631b9a7cfbbe5b6142775b8b (diff) | |
download | busybox-w32-420f5edfe7676fe6e7cddbbf15c04649d096e422.tar.gz busybox-w32-420f5edfe7676fe6e7cddbbf15c04649d096e422.tar.bz2 busybox-w32-420f5edfe7676fe6e7cddbbf15c04649d096e422.zip |
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.
-rw-r--r-- | win32/mingw.c | 27 |
1 files changed, 27 insertions, 0 deletions
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 | |||
862 | t = newfmt + m + 1; | 862 | t = newfmt + m + 1; |
863 | fmt = newfmt; | 863 | fmt = newfmt; |
864 | } | 864 | } |
865 | else if ( t[1] == 'z' ) { | ||
866 | char buffer[16] = ""; | ||
867 | |||
868 | *t = '\0'; | ||
869 | m = t - fmt; | ||
870 | _tzset(); | ||
871 | if ( tm->tm_isdst >= 0 ) { | ||
872 | int offset = (int)_timezone - (tm->tm_isdst > 0 ? 3600 : 0); | ||
873 | int hr, min; | ||
874 | |||
875 | if ( offset > 0 ) { | ||
876 | buffer[0] = '-'; | ||
877 | } | ||
878 | else { | ||
879 | buffer[0] = '+'; | ||
880 | offset = -offset; | ||
881 | } | ||
882 | |||
883 | hr = offset / 3600; | ||
884 | min = (offset % 3600) / 60; | ||
885 | sprintf(buffer+1, "%02d%02d", hr, min); | ||
886 | } | ||
887 | newfmt = xasprintf("%s%s%s", fmt, buffer, t+2); | ||
888 | free(fmt); | ||
889 | t = newfmt + m + 1; | ||
890 | fmt = newfmt; | ||
891 | } | ||
865 | else if ( t[1] != '\0' ) { | 892 | else if ( t[1] != '\0' ) { |
866 | ++t; | 893 | ++t; |
867 | } | 894 | } |