Skip to content

Commit ddde44d

Browse files
committed
Fix iso 8601 time handling
This must not depend on local timezone in any way, so use timegm instead of mktime and take parsed timezone into account so both e.g. 2013-08-02T02:09:39Z and 2013-08-02T06:09:39+0400 are correctly parsed as 1375409379.
1 parent adf47da commit ddde44d

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

src/osm.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,13 @@ static
9393
time_t convert_iso8601(const char *str) {
9494
if(!str) return 0;
9595

96-
tzset();
97-
9896
struct tm ctime;
9997
memset(&ctime, 0, sizeof(struct tm));
10098
strptime(str, "%FT%T%z", &ctime);
101-
102-
#ifdef __FreeBSD__ // XXX: TEMPORARY HACK TO MAKE IT COMPILE ON MY DESKTOP // AMDmi3
103-
return mktime(&ctime);
104-
#else
105-
return mktime(&ctime) - timezone;
106-
#endif
99+
100+
long gmtoff = ctime.tm_gmtoff;
101+
102+
return timegm(&ctime) - gmtoff;
107103
}
108104

109105
/* -------------------- tag handling ----------------------- */

0 commit comments

Comments
 (0)