# HG changeset patch # User Adam Chlipala # Date 1293650216 18000 # Node ID 04bd0d91b74cc07791c0aec6f38eb5c44b755d42 # Parent 268d9af9103fe3d9b6862e09b167c98dd7cd6d19 Latest attempt to get readUtc working properly diff -r 268d9af9103f -r 04bd0d91b74c src/c/urweb.c --- a/src/c/urweb.c Tue Dec 28 14:51:57 2010 -0500 +++ b/src/c/urweb.c Wed Dec 29 14:16:56 2010 -0500 @@ -3662,13 +3662,22 @@ } uw_Basis_time *uw_Basis_readUtc(uw_context ctx, uw_Basis_string s) { - uw_Basis_time *r = uw_Basis_stringToTime(ctx, s); - - if (r) { - struct tm tm; - localtime_r(&r->seconds, &tm); - r->seconds -= tm.tm_gmtoff; - } - - return r; + 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)) { + uw_Basis_time *r = uw_malloc(ctx, sizeof(uw_Basis_time)); + + r->microseconds = 0; + + t = mktime(&tm); + localtime_r(&t, &tm2); + + tm.tm_sec += tm2.tm_gmtoff; + r->seconds = mktime(&tm); + + return r; + } else + return NULL; }