From f5c0c4d787af10f22c35134e605242a48f9cc17b Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Tue, 31 Jul 2018 11:40:11 -0400 Subject: [PATCH] Fix offsetting local time back to UTC. --- platform-independent/c/core/src/mpw-marshal-util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform-independent/c/core/src/mpw-marshal-util.c b/platform-independent/c/core/src/mpw-marshal-util.c index eca589c9..cfbd0a7e 100644 --- a/platform-independent/c/core/src/mpw-marshal-util.c +++ b/platform-independent/c/core/src/mpw-marshal-util.c @@ -35,8 +35,7 @@ char *mpw_get_token(const char **in, const char *eol, char *delim) { return token; } -time_t mpw_timegm( - const char *time) { +time_t mpw_timegm(const char *time) { // TODO: Support for parsing non-UTC time strings // Parse time as a UTC timestamp, into a tm. @@ -49,7 +48,8 @@ time_t mpw_timegm( // mktime interprets tm as being local, we need to offset back to UTC (timegm/tm_gmtoff are non-standard). time_t local_time = mktime( &tm ), local_dst = tm.tm_isdst > 0? 3600: 0; - return local_time + local_dst - mktime( gmtime( &local_time ) ); + time_t gmtoff = local_time + local_dst - mktime( gmtime( &local_time ) ); + return local_time + gmtoff; } return false;