From 6a164e6f70af4e2677dc77eb1faeefe9dc1e8d01 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Wed, 29 Dec 2010 14:16:56 -0500 Subject: Latest attempt to get readUtc working properly --- src/c/urweb.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/c/urweb.c b/src/c/urweb.c index 2858fefc..ec78e662 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -3662,13 +3662,22 @@ uw_Basis_bool uw_Basis_le_time(uw_context ctx, uw_Basis_time t1, uw_Basis_time t } uw_Basis_time *uw_Basis_readUtc(uw_context ctx, uw_Basis_string s) { - uw_Basis_time *r = uw_Basis_stringToTime(ctx, s); + struct tm tm, tm2; + time_t t; - if (r) { - struct tm tm; - localtime_r(&r->seconds, &tm); - r->seconds -= tm.tm_gmtoff; - } + 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)); - return r; + 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; } -- cgit v1.2.3