summaryrefslogtreecommitdiff
path: root/src/c/urweb.c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2010-12-29 14:16:56 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2010-12-29 14:16:56 -0500
commit6a164e6f70af4e2677dc77eb1faeefe9dc1e8d01 (patch)
tree4ee74fbbd2c6145239522aa0142000d943a2fa6d /src/c/urweb.c
parentc3a91028d8cb4c5e47996cf5baf55778769acb75 (diff)
Latest attempt to get readUtc working properly
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r--src/c/urweb.c23
1 files 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;
}