comparison src/c/urweb.c @ 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
comparison
equal deleted inserted replaced
1372:268d9af9103f 1373:04bd0d91b74c
3660 uw_Basis_bool uw_Basis_le_time(uw_context ctx, uw_Basis_time t1, uw_Basis_time t2) { 3660 uw_Basis_bool uw_Basis_le_time(uw_context ctx, uw_Basis_time t1, uw_Basis_time t2) {
3661 return !!(uw_Basis_eq_time(ctx, t1, t2) || uw_Basis_lt_time(ctx, t1, t2)); 3661 return !!(uw_Basis_eq_time(ctx, t1, t2) || uw_Basis_lt_time(ctx, t1, t2));
3662 } 3662 }
3663 3663
3664 uw_Basis_time *uw_Basis_readUtc(uw_context ctx, uw_Basis_string s) { 3664 uw_Basis_time *uw_Basis_readUtc(uw_context ctx, uw_Basis_string s) {
3665 uw_Basis_time *r = uw_Basis_stringToTime(ctx, s); 3665 struct tm tm, tm2;
3666 3666 time_t t;
3667 if (r) { 3667
3668 struct tm tm; 3668 char *other = uw_Basis_strcat(ctx, s, " UTC");
3669 localtime_r(&r->seconds, &tm); 3669 if (strptime(other, TIME_FMT " %Z", &tm) || strptime(other, TIME_FMT_PG " %Z", &tm)) {
3670 r->seconds -= tm.tm_gmtoff; 3670 uw_Basis_time *r = uw_malloc(ctx, sizeof(uw_Basis_time));
3671 } 3671
3672 3672 r->microseconds = 0;
3673 return r; 3673
3674 } 3674 t = mktime(&tm);
3675 localtime_r(&t, &tm2);
3676
3677 tm.tm_sec += tm2.tm_gmtoff;
3678 r->seconds = mktime(&tm);
3679
3680 return r;
3681 } else
3682 return NULL;
3683 }