Rewrite mu_utc_offset in a more portable (hopefully) way.
Showing
1 changed file
with
9 additions
and
2 deletions
... | @@ -20,10 +20,17 @@ | ... | @@ -20,10 +20,17 @@ |
20 | #endif | 20 | #endif |
21 | #include <time.h> | 21 | #include <time.h> |
22 | 22 | ||
23 | #define TMSEC(t) (((t)->tm_hour * 60 + (t)->tm_min) * 60 + (t)->tm_sec) | ||
24 | |||
23 | /* Returns the offset of our timezone from UTC, in seconds. */ | 25 | /* Returns the offset of our timezone from UTC, in seconds. */ |
24 | int | 26 | int |
25 | mu_utc_offset (void) | 27 | mu_utc_offset (void) |
26 | { | 28 | { |
27 | tzset (); | 29 | time_t t = time (NULL); |
28 | return - timezone; | 30 | struct tm ltm = *localtime (&t); |
31 | struct tm gtm = *gmtime (&t); | ||
32 | int d = TMSEC (<m) - TMSEC (>m); | ||
33 | if (!(ltm.tm_year = gtm.tm_year && ltm.tm_mon == gtm.tm_mon)) | ||
34 | d += 86400; | ||
35 | return d; | ||
29 | } | 36 | } | ... | ... |
-
Please register or sign in to post a comment