diff options
author | Adam Chlipala <adam@chlipala.net> | 2014-09-20 13:55:25 -0400 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2014-09-20 13:55:25 -0400 |
commit | 745a1e34ec9067a8c807971b01d65c350f8e5286 (patch) | |
tree | 5ced1f7db6e337204ab34d54dc653437ef53af38 | |
parent | 4e2c3a1424a9b8f242953cd74c47bf641e84504d (diff) |
Default to parsing time strings with the application-configured format
-rw-r--r-- | src/c/urweb.c | 15 | ||||
-rw-r--r-- | tests/timeRoundTrip.ur | 3 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c index d7bc05e3..09514afa 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -2897,13 +2897,17 @@ uw_Basis_time *uw_Basis_stringToTime(uw_context ctx, uw_Basis_string s) { } } else { - if (strptime(s, TIME_FMT_PG, &stm) == end) { + if (strptime(s, ctx->app->time_format, &stm) == end) { uw_Basis_time *r = uw_malloc(ctx, sizeof(uw_Basis_time)); r->seconds = mktime(&stm); r->microseconds = 0; return r; - } - else if (strptime(s, TIME_FMT, &stm) == end) { + } else if (strptime(s, TIME_FMT_PG, &stm) == end) { + uw_Basis_time *r = uw_malloc(ctx, sizeof(uw_Basis_time)); + r->seconds = mktime(&stm); + r->microseconds = 0; + return r; + } else if (strptime(s, TIME_FMT, &stm) == end) { uw_Basis_time *r = uw_malloc(ctx, sizeof(uw_Basis_time)); r->seconds = mktime(&stm); r->microseconds = 0; @@ -3047,7 +3051,10 @@ uw_Basis_time uw_Basis_stringToTime_error(uw_context ctx, uw_Basis_string s) { } } else { - if (strptime(s, TIME_FMT_PG, &stm) == end) { + if (strptime(s, ctx->app->time_format, &stm) == end) { + uw_Basis_time r = { mktime(&stm) }; + return r; + } else if (strptime(s, TIME_FMT_PG, &stm) == end) { uw_Basis_time r = { mktime(&stm) }; return r; } else if (strptime(s, TIME_FMT, &stm) == end) { diff --git a/tests/timeRoundTrip.ur b/tests/timeRoundTrip.ur new file mode 100644 index 00000000..d20e61e8 --- /dev/null +++ b/tests/timeRoundTrip.ur @@ -0,0 +1,3 @@ +fun main () : transaction page = + t <- now; + return <xml>{[readError (show t) : time]}</xml> |