-rw-r--r-- | lib/util.cc | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/util.cc b/lib/util.cc index d979502..a46ba2a 100644 --- a/lib/util.cc +++ b/lib/util.cc @@ -123,4 +123,19 @@ namespace opkele { } +#ifndef HAVE_TIMEGM + static time_t timegm(struct tm *t) { + char *tz = getenv("TZ"); + setenv("TZ","",1); tzset(); + time_t rv = mktime(t); + if(tz) + setenv("TZ",tz,1); + else + unsetenv("TZ"); + tzset(); + return rv; + } +# define timegm opkele::util::timegm +#endif /* HAVE_TIMEGM */ + time_t w3c_to_time(const string& w) { int fraction; @@ -146,8 +161,8 @@ namespace opkele { tm_t.tm_mon--; tm_t.tm_year-=1900; - time_t rv = mktime(&tm_t); + time_t rv = timegm(&tm_t); if(rv==(time_t)-1) - throw failed_conversion(OPKELE_CP_ "failed to mktime()"); - return rv-timezone; + throw failed_conversion(OPKELE_CP_ "failed to gmtime()"); + return rv; } |