Mercurial > urweb
comparison src/c/urweb.c @ 1629:438561303d02
timeFormat .urp directive
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 04 Dec 2011 14:40:12 -0500 |
parents | 43f22a8f76cc |
children | 4682b312e9d5 |
comparison
equal
deleted
inserted
replaced
1628:3621f486ce72 | 1629:438561303d02 |
---|---|
2149 } | 2149 } |
2150 | 2150 |
2151 #define TIME_FMT "%x %X" | 2151 #define TIME_FMT "%x %X" |
2152 #define TIME_FMT_PG "%Y-%m-%d %T" | 2152 #define TIME_FMT_PG "%Y-%m-%d %T" |
2153 | 2153 |
2154 uw_Basis_string uw_Basis_timeToString(uw_context, uw_Basis_time); | |
2155 | |
2154 uw_Basis_string uw_Basis_htmlifyTime(uw_context ctx, uw_Basis_time t) { | 2156 uw_Basis_string uw_Basis_htmlifyTime(uw_context ctx, uw_Basis_time t) { |
2155 size_t len; | 2157 return uw_Basis_htmlifyString(ctx, uw_Basis_timeToString(ctx, t)); |
2156 char *r; | |
2157 struct tm stm = {}; | |
2158 stm.tm_isdst = -1; | |
2159 | |
2160 if (localtime_r(&t.seconds, &stm)) { | |
2161 uw_check_heap(ctx, TIMES_MAX); | |
2162 r = ctx->heap.front; | |
2163 len = strftime(r, TIMES_MAX, TIME_FMT, &stm); | |
2164 ctx->heap.front += len+1; | |
2165 return r; | |
2166 } else | |
2167 return "<i>Invalid time</i>"; | |
2168 } | 2158 } |
2169 | 2159 |
2170 uw_unit uw_Basis_htmlifyTime_w(uw_context ctx, uw_Basis_time t) { | 2160 uw_unit uw_Basis_htmlifyTime_w(uw_context ctx, uw_Basis_time t) { |
2171 size_t len; | 2161 return uw_Basis_htmlifyString_w(ctx, uw_Basis_timeToString(ctx, t)); |
2172 char *r; | |
2173 struct tm stm = {}; | |
2174 stm.tm_isdst = -1; | |
2175 | |
2176 if (localtime_r(&t.seconds, &stm)) { | |
2177 uw_check(ctx, TIMES_MAX); | |
2178 r = ctx->page.front; | |
2179 len = strftime(r, TIMES_MAX, TIME_FMT, &stm); | |
2180 ctx->page.front += len; | |
2181 } else { | |
2182 uw_check(ctx, 20); | |
2183 strcpy(ctx->page.front, "<i>Invalid time</i>"); | |
2184 ctx->page.front += 19; | |
2185 } | |
2186 | |
2187 return uw_unit_v; | |
2188 } | 2162 } |
2189 | 2163 |
2190 char *uw_Basis_htmlifySource(uw_context ctx, uw_Basis_source src) { | 2164 char *uw_Basis_htmlifySource(uw_context ctx, uw_Basis_source src) { |
2191 int len; | 2165 int len; |
2192 char *r; | 2166 char *r; |
2722 return "False"; | 2696 return "False"; |
2723 else | 2697 else |
2724 return "True"; | 2698 return "True"; |
2725 } | 2699 } |
2726 | 2700 |
2727 uw_Basis_string uw_Basis_timeToString(uw_context ctx, uw_Basis_time t) { | |
2728 size_t len; | |
2729 char *r; | |
2730 struct tm stm = {}; | |
2731 stm.tm_isdst = -1; | |
2732 | |
2733 if (localtime_r(&t.seconds, &stm)) { | |
2734 uw_check_heap(ctx, TIMES_MAX); | |
2735 r = ctx->heap.front; | |
2736 len = strftime(r, TIMES_MAX, TIME_FMT, &stm); | |
2737 ctx->heap.front += len+1; | |
2738 return r; | |
2739 } else | |
2740 return "<Invalid time>"; | |
2741 } | |
2742 | |
2743 uw_Basis_string uw_Basis_timef(uw_context ctx, const char *fmt, uw_Basis_time t) { | 2701 uw_Basis_string uw_Basis_timef(uw_context ctx, const char *fmt, uw_Basis_time t) { |
2744 size_t len; | 2702 size_t len; |
2745 char *r; | 2703 char *r; |
2746 struct tm stm = {}; | 2704 struct tm stm = {}; |
2747 stm.tm_isdst = -1; | 2705 stm.tm_isdst = -1; |
2752 len = strftime(r, TIMES_MAX, fmt, &stm); | 2710 len = strftime(r, TIMES_MAX, fmt, &stm); |
2753 ctx->heap.front += len+1; | 2711 ctx->heap.front += len+1; |
2754 return r; | 2712 return r; |
2755 } else | 2713 } else |
2756 return "<Invalid time>"; | 2714 return "<Invalid time>"; |
2715 } | |
2716 | |
2717 uw_Basis_string uw_Basis_timeToString(uw_context ctx, uw_Basis_time t) { | |
2718 return uw_Basis_timef(ctx, ctx->app->time_format, t); | |
2757 } | 2719 } |
2758 | 2720 |
2759 uw_Basis_int *uw_Basis_stringToInt(uw_context ctx, uw_Basis_string s) { | 2721 uw_Basis_int *uw_Basis_stringToInt(uw_context ctx, uw_Basis_string s) { |
2760 char *endptr; | 2722 char *endptr; |
2761 uw_Basis_int n = strtoll(s, &endptr, 10); | 2723 uw_Basis_int n = strtoll(s, &endptr, 10); |