changeset 1373:04bd0d91b74c

Latest attempt to get readUtc working properly
author Adam Chlipala <adam@chlipala.net>
date Wed, 29 Dec 2010 14:16:56 -0500
parents 268d9af9103f
children 8cdd25f9cfd0
files src/c/urweb.c
diffstat 1 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }