summaryrefslogtreecommitdiff
path: root/src/c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-12-04 14:40:12 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2011-12-04 14:40:12 -0500
commit64adfd7ff1361a1886d689f03b5e30780df9e691 (patch)
tree86de944318bf3610af01258c455ceacfd450c307 /src/c
parent470cb13dcf7e4a40a4155ba187b25718770d9189 (diff)
timeFormat .urp directive
Diffstat (limited to 'src/c')
-rw-r--r--src/c/urweb.c54
1 files changed, 8 insertions, 46 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 8ebd9a2f..270443c6 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -2151,40 +2151,14 @@ 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"
-uw_Basis_string uw_Basis_htmlifyTime(uw_context ctx, uw_Basis_time t) {
- size_t len;
- char *r;
- struct tm stm = {};
- stm.tm_isdst = -1;
+uw_Basis_string uw_Basis_timeToString(uw_context, uw_Basis_time);
- if (localtime_r(&t.seconds, &stm)) {
- uw_check_heap(ctx, TIMES_MAX);
- r = ctx->heap.front;
- len = strftime(r, TIMES_MAX, TIME_FMT, &stm);
- ctx->heap.front += len+1;
- return r;
- } else
- return "<i>Invalid time</i>";
+uw_Basis_string uw_Basis_htmlifyTime(uw_context ctx, uw_Basis_time t) {
+ return uw_Basis_htmlifyString(ctx, uw_Basis_timeToString(ctx, t));
}
uw_unit uw_Basis_htmlifyTime_w(uw_context ctx, uw_Basis_time t) {
- size_t len;
- char *r;
- struct tm stm = {};
- stm.tm_isdst = -1;
-
- if (localtime_r(&t.seconds, &stm)) {
- uw_check(ctx, TIMES_MAX);
- r = ctx->page.front;
- len = strftime(r, TIMES_MAX, TIME_FMT, &stm);
- ctx->page.front += len;
- } else {
- uw_check(ctx, 20);
- strcpy(ctx->page.front, "<i>Invalid time</i>");
- ctx->page.front += 19;
- }
-
- return uw_unit_v;
+ return uw_Basis_htmlifyString_w(ctx, uw_Basis_timeToString(ctx, t));
}
char *uw_Basis_htmlifySource(uw_context ctx, uw_Basis_source src) {
@@ -2724,22 +2698,6 @@ uw_Basis_string uw_Basis_boolToString(uw_context ctx, uw_Basis_bool b) {
return "True";
}
-uw_Basis_string uw_Basis_timeToString(uw_context ctx, uw_Basis_time t) {
- size_t len;
- char *r;
- struct tm stm = {};
- stm.tm_isdst = -1;
-
- if (localtime_r(&t.seconds, &stm)) {
- uw_check_heap(ctx, TIMES_MAX);
- r = ctx->heap.front;
- len = strftime(r, TIMES_MAX, TIME_FMT, &stm);
- ctx->heap.front += len+1;
- return r;
- } else
- return "<Invalid time>";
-}
-
uw_Basis_string uw_Basis_timef(uw_context ctx, const char *fmt, uw_Basis_time t) {
size_t len;
char *r;
@@ -2756,6 +2714,10 @@ uw_Basis_string uw_Basis_timef(uw_context ctx, const char *fmt, uw_Basis_time t)
return "<Invalid time>";
}
+uw_Basis_string uw_Basis_timeToString(uw_context ctx, uw_Basis_time t) {
+ return uw_Basis_timef(ctx, ctx->app->time_format, t);
+}
+
uw_Basis_int *uw_Basis_stringToInt(uw_context ctx, uw_Basis_string s) {
char *endptr;
uw_Basis_int n = strtoll(s, &endptr, 10);