summaryrefslogtreecommitdiff
path: root/src/c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-12-04 16:32:06 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2011-12-04 16:32:06 -0500
commitb2d1c581afdb7ad9ede5d43158306c45177ef560 (patch)
treea839986fce23c2a41291040eb9e1f6b74c6ab787 /src/c
parent30fa60cba0832e7530c8d29c056a6158b907e7f3 (diff)
Fix client-side [int] parsing and extend server-side [time] parsing to support a format that also works portably in JavaScript
Diffstat (limited to 'src/c')
-rw-r--r--src/c/urweb.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 270443c6..c71baee1 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -2150,6 +2150,7 @@ uw_unit uw_Basis_htmlifyBool_w(uw_context ctx, uw_Basis_bool b) {
#define TIME_FMT "%x %X"
#define TIME_FMT_PG "%Y-%m-%d %T"
+#define TIME_FMT_JS "%Y/%m/%d %T"
uw_Basis_string uw_Basis_timeToString(uw_context, uw_Basis_time);
@@ -2799,6 +2800,11 @@ uw_Basis_time *uw_Basis_stringToTime(uw_context ctx, uw_Basis_string s) {
r->seconds = mktime(&stm);
r->microseconds = 0;
return r;
+ } else if (strptime(s, TIME_FMT_JS, &stm) == end) {
+ uw_Basis_time *r = uw_malloc(ctx, sizeof(uw_Basis_time));
+ r->seconds = mktime(&stm);
+ r->microseconds = 0;
+ return r;
}
else
return NULL;
@@ -2939,6 +2945,9 @@ uw_Basis_time uw_Basis_stringToTime_error(uw_context ctx, uw_Basis_string s) {
} else if (strptime(s, TIME_FMT, &stm) == end) {
uw_Basis_time r = { mktime(&stm) };
return r;
+ } else if (strptime(s, TIME_FMT_JS, &stm) == end) {
+ uw_Basis_time r = { mktime(&stm) };
+ return r;
} else
uw_error(ctx, FATAL, "Can't parse time: %s", uw_Basis_htmlifyString(ctx, s));
}
@@ -3883,7 +3892,7 @@ uw_Basis_time *uw_Basis_readUtc(uw_context ctx, uw_Basis_string s) {
char *end = strchr(s, 0);
stm.tm_isdst = -1;
- if (strptime(s, TIME_FMT_PG, &stm) == end || strptime(s, TIME_FMT, &stm) == end) {
+ if (strptime(s, TIME_FMT_PG, &stm) == end || strptime(s, TIME_FMT, &stm) == end || strptime(s, TIME_FMT_JS, &stm) == end) {
uw_Basis_time *r = uw_malloc(ctx, sizeof(uw_Basis_time));
r->seconds = timegm(&stm);