author | Michael Krelin <hacker@klever.net> | 2008-06-29 16:08:01 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-06-29 16:11:44 (UTC) |
commit | 12837594b705ad10fdadfd0ba1bfc2249b3b1264 (patch) (side-by-side diff) | |
tree | e0502e678b09668ec59828237ebf5972014d0ce0 /lib | |
parent | 362678728b8232c9490e14ba14ff323d9a92d6be (diff) | |
download | libopkele-12837594b705ad10fdadfd0ba1bfc2249b3b1264.zip libopkele-12837594b705ad10fdadfd0ba1bfc2249b3b1264.tar.gz libopkele-12837594b705ad10fdadfd0ba1bfc2249b3b1264.tar.bz2 |
Fixed w3c to unix timestamp conversion for FreeBSD
Thanks to Göran Löwkrantz for pointing both to the problem and possible
solution.
Signed-off-by: Michael Krelin <hacker@klever.net>
-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 @@ -119,12 +119,27 @@ namespace opkele { char rv[25]; if(!strftime(rv,sizeof(rv)-1,"%Y-%m-%dT%H:%M:%SZ",&tm_t)) throw failed_conversion(OPKELE_CP_ "failed to strftime()"); return rv; } +#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; struct tm tm_t; memset(&tm_t,0,sizeof(tm_t)); if( ( sscanf( @@ -142,16 +157,16 @@ namespace opkele { &fraction ) != 7 ) ) throw failed_conversion(OPKELE_CP_ "failed to sscanf()"); 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; } /* * */ |