aboutsummaryrefslogtreecommitdiff
path: root/libbb/time.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-09-17 09:18:58 +0100
committerRon Yorston <rmy@pobox.com>2021-09-17 11:41:25 +0100
commit9e16eecc70020e9a603d637f6a8fdfc7c95c30e1 (patch)
tree5700c068c09ad6028551449c2c9deac13b5c3b32 /libbb/time.c
parent46299d0c4f4c9a4bbad38bbbe26f196e1bccdc52 (diff)
downloadbusybox-w32-9e16eecc70020e9a603d637f6a8fdfc7c95c30e1.tar.gz
busybox-w32-9e16eecc70020e9a603d637f6a8fdfc7c95c30e1.tar.bz2
busybox-w32-9e16eecc70020e9a603d637f6a8fdfc7c95c30e1.zip
win32: changes to allow timezones in dates
Create mingw_strptime() to return timezone offset as a separate argument (since Microsoft's struct tm doesn't have the required member). Import timegm() from musl. Update parse_datestr() to use mingw_strptime(). Enable FEATURE_TIMEZONE in the default configuration. GitHub issue #230.
Diffstat (limited to 'libbb/time.c')
-rw-r--r--libbb/time.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/libbb/time.c b/libbb/time.c
index 41a69c754..ed4f50470 100644
--- a/libbb/time.c
+++ b/libbb/time.c
@@ -43,7 +43,12 @@ int FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
43 save = *ptm; 43 save = *ptm;
44 fmt = fmt_str; 44 fmt = fmt_str;
45 while (*fmt) { 45 while (*fmt) {
46#if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_TIMEZONE
47 long gmtoff;
48 endp = mingw_strptime(date_str, fmt, ptm, &gmtoff);
49#else
46 endp = strptime(date_str, fmt, ptm); 50 endp = strptime(date_str, fmt, ptm);
51#endif
47 if (endp && *endp == '\0') { 52 if (endp && *endp == '\0') {
48#if ENABLE_FEATURE_TIMEZONE 53#if ENABLE_FEATURE_TIMEZONE
49 if (strchr(fmt, 'z')) { 54 if (strchr(fmt, 'z')) {
@@ -51,7 +56,11 @@ int FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
51 struct tm *utm; 56 struct tm *utm;
52 57
53 /* we have timezone offset: obtain Unix time_t */ 58 /* we have timezone offset: obtain Unix time_t */
59#if ENABLE_PLATFORM_MINGW32
60 ptm->tm_sec -= gmtoff;
61#else
54 ptm->tm_sec -= ptm->tm_gmtoff; 62 ptm->tm_sec -= ptm->tm_gmtoff;
63#endif
55 ptm->tm_isdst = 0; 64 ptm->tm_isdst = 0;
56 t = timegm(ptm); 65 t = timegm(ptm);
57 if (t == (time_t)-1) 66 if (t == (time_t)-1)