From 028cd4960d481494950f38e5e1ab1801adcec282 Mon Sep 17 00:00:00 2001 From: Doug Currie Date: Wed, 16 Nov 2016 10:52:58 -0500 Subject: [PATCH] Fix parsetime to initialize timezone, issue #34. --- llt/timefuncs.c | 4 +++- tests/unittest.lsp | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/llt/timefuncs.c b/llt/timefuncs.c index 1b4b41c..09ddeb8 100644 --- a/llt/timefuncs.c +++ b/llt/timefuncs.c @@ -82,7 +82,7 @@ void timestring(double seconds, char *buffer, size_t len) { time_t tme = (time_t)seconds; -#ifdef LINUX +#if defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD) char *fmt = "%c"; /* needed to suppress GCC warning */ struct tm tm; @@ -117,6 +117,8 @@ double parsetime(const char *str) res = strptime(str, fmt, &tm); if (res != NULL) { + tm.tm_isdst = -1; /* Not set by strptime(); tells mktime() to determine + whether daylight saving time is in effect */ t = mktime(&tm); if (t == ((time_t)-1)) return -1; diff --git a/tests/unittest.lsp b/tests/unittest.lsp index 38891b0..0170fe6 100644 --- a/tests/unittest.lsp +++ b/tests/unittest.lsp @@ -283,5 +283,9 @@ (assert (not (equal? (hash (iota 41)) (hash (iota 42))))) +(if (top-level-bound? 'time.fromstring) + (assert (let ((ts (time.string (time.now)))) + (eqv? ts (time.string (time.fromstring ts)))))) + (princ "all tests pass\n") #t