# HG changeset patch # User Adam Chlipala # Date 1293656334 18000 # Node ID 8cdd25f9cfd0cde664f8e601bcb941317b3bd680 # Parent 04bd0d91b74cc07791c0aec6f38eb5c44b755d42 Next attempt at getting time parsing right diff -r 04bd0d91b74c -r 8cdd25f9cfd0 src/c/urweb.c --- a/src/c/urweb.c Wed Dec 29 14:16:56 2010 -0500 +++ b/src/c/urweb.c Wed Dec 29 15:58:54 2010 -0500 @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -2694,7 +2695,7 @@ uw_Basis_time *uw_Basis_stringToTime(uw_context ctx, uw_Basis_string s) { char *dot = strchr(s, '.'), *end = strchr(s, 0); - struct tm stm; + struct tm stm = {}; if (dot) { *dot = 0; @@ -2730,7 +2731,7 @@ uw_Basis_time *uw_Basis_stringToTimef(uw_context ctx, const char *fmt, uw_Basis_string s) { char *end = strchr(s, 0); - struct tm stm; + struct tm stm = {}; if (strptime(s, fmt, &stm) == end) { uw_Basis_time *r = uw_malloc(ctx, sizeof(uw_Basis_time)); @@ -3661,23 +3662,28 @@ return !!(uw_Basis_eq_time(ctx, t1, t2) || uw_Basis_lt_time(ctx, t1, t2)); } +/*uw_Basis_time *uw_Basis_readUtc(uw_context ctx, uw_Basis_string s) { + uw_Basis_time *r = uw_Basis_stringToTime(ctx, s); + + printf("timezone = %ld\n", timezone); + + if (r) + r->seconds -= timezone; + + return r; +}*/ + uw_Basis_time *uw_Basis_readUtc(uw_context ctx, uw_Basis_string s) { - struct tm tm, tm2; - time_t t; - - char *other = uw_Basis_strcat(ctx, s, " UTC"); - if (strptime(other, TIME_FMT " %Z", &tm) || strptime(other, TIME_FMT_PG " %Z", &tm)) { + struct tm stm = {}; + + if (strptime(s, TIME_FMT_PG, &stm) || strptime(s, TIME_FMT, &stm)) { uw_Basis_time *r = uw_malloc(ctx, sizeof(uw_Basis_time)); - + stm.tm_hour -= timezone / (60 * 60); + r->seconds = mktime(&stm); r->microseconds = 0; - t = mktime(&tm); - localtime_r(&t, &tm2); - - tm.tm_sec += tm2.tm_gmtoff; - r->seconds = mktime(&tm); - return r; - } else + } + else return NULL; }