Fix parsetime to initialize timezone, issue #34.

This commit is contained in:
Doug Currie 2016-11-16 10:52:58 -05:00
parent 8342f9a1e9
commit b36d4fbf5d
2 changed files with 7 additions and 1 deletions

View File

@ -82,7 +82,7 @@ void timestring(double seconds, char *buffer, size_t len)
{ {
time_t tme = (time_t)seconds; 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 */ char *fmt = "%c"; /* needed to suppress GCC warning */
struct tm tm; struct tm tm;
@ -117,6 +117,8 @@ double parsetime(const char *str)
res = strptime(str, fmt, &tm); res = strptime(str, fmt, &tm);
if (res != NULL) { 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); t = mktime(&tm);
if (t == ((time_t)-1)) if (t == ((time_t)-1))
return -1; return -1;

View File

@ -283,5 +283,9 @@
(assert (not (equal? (hash (iota 41)) (assert (not (equal? (hash (iota 41))
(hash (iota 42))))) (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") (princ "all tests pass\n")
#t #t