Created
July 8, 2013 22:02
-
-
Save krig/5952867 to your computer and use it in GitHub Desktop.
(hopefully) fixed iso8601 parser. Should work in GNU/Linux systems now, at least.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* parses only YYYY-MM-DDTHH:MM:SSZ */ | |
time_t | |
parseiso8601utc_fixed(const char *date) | |
{ | |
struct tm tt = {0}; | |
double seconds; | |
if (sscanf(date, "%04d-%02d-%02dT%02d:%02d:%lfZ", | |
&tt.tm_year, &tt.tm_mon, &tt.tm_mday, | |
&tt.tm_hour, &tt.tm_min, &seconds) != 6) | |
return -1; | |
tt.tm_year -= 1900; | |
tt.tm_isdst = 0; | |
tt.tm_sec = (int)seconds; | |
tt.tm_mon--; | |
return timegm(&tt); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment