diff options
author | Sven Moritz Hallberg <pesco@khjk.org> | 2010-06-03 13:00:45 +0200 |
---|---|---|
committer | Sven Moritz Hallberg <pesco@khjk.org> | 2010-06-03 13:00:45 +0200 |
commit | 814aa52228c7cad1d036c1a6dc5ea03cce61c048 (patch) | |
tree | 7db06b9191f00b086f25789a0a040d15cef580cf /lib/misc.c | |
parent | 5f8ab6a9adf09ea7c07f728227bdb6d3953588f1 (diff) | |
parent | f4bcc223fea70de8555bbc4d2caf48e0476c0e13 (diff) |
merge in bitlbee 1.2.6
Diffstat (limited to 'lib/misc.c')
-rw-r--r-- | lib/misc.c | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -78,6 +78,41 @@ time_t get_time(int year, int month, int day, int hour, int min, int sec) return mktime(&tm); } +time_t mktime_utc( struct tm *tp ) +{ + struct tm utc; + time_t res, tres; + + tp->tm_isdst = -1; + res = mktime( tp ); + /* Problem is, mktime() just gave us the GMT timestamp for the + given local time... While the given time WAS NOT local. So + we should fix this now. + + Now I could choose between messing with environment variables + (kludgy) or using timegm() (not portable)... Or doing the + following, which I actually prefer... + + tzset() may also work but in other places I actually want to + use local time. + + FFFFFFFFFFFFFFFFFFFFFUUUUUUUUUUUUUUUUUUUU!! */ + gmtime_r( &res, &utc ); + utc.tm_isdst = -1; + if( utc.tm_hour == tp->tm_hour && utc.tm_min == tp->tm_min ) + /* Sweet! We're in UTC right now... */ + return res; + + tres = mktime( &utc ); + res += res - tres; + + /* Yes, this is a hack. And it will go wrong around DST changes. + BUT this is more likely to be threadsafe than messing with + environment variables, and possibly more portable... */ + + return res; +} + typedef struct htmlentity { char code[7]; |