* When saving a Task, if the status is COMPLETED then also set PERCENT-COMPLETE:100...
[citadel.git] / webcit / http_datestring.c
blobf3db04ce9783427b1d5ed8060121eebb37b4e389
1 /*
2 * $Id$
3 */
4 /**
5 * \defgroup HTTPDateTime Function to generate HTTP-compliant textual time/date stamp
6 * (This module was lifted directly from the Citadel server source)
8 * \ingroup WebcitHttpServer
9 */
10 /*@{*/
11 #include "webcit.h"
13 /** HTTP Months - do not translate - these are not for human consumption */
14 static char *httpdate_months[] = {
15 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
16 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
19 /** HTTP Weekdays - do not translate - these are not for human consumption */
20 static char *httpdate_weekdays[] = {
21 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
25 /**
26 * \brief Supplied with a unix timestamp, generate a textual time/date stamp
27 * \param buf the return buffer
28 * \param n the size of the buffer
29 * \param xtime the time to format as string
31 void http_datestring(char *buf, size_t n, time_t xtime) {
32 struct tm t;
34 long offset;
35 char offsign;
37 localtime_r(&xtime, &t);
39 /** Convert "seconds west of GMT" to "hours/minutes offset" */
40 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
41 offset = t.tm_gmtoff;
42 #else
43 offset = timezone;
44 #endif
45 if (offset > 0) {
46 offsign = '+';
48 else {
49 offset = 0L - offset;
50 offsign = '-';
52 offset = ( (offset / 3600) * 100 ) + ( offset % 60 );
54 snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
55 httpdate_weekdays[t.tm_wday],
56 t.tm_mday,
57 httpdate_months[t.tm_mon],
58 t.tm_year + 1900,
59 t.tm_hour,
60 t.tm_min,
61 t.tm_sec,
62 offsign, offset
67 void tmplput_nowstr(StrBuf *Target, WCTemplputParams *TP)
69 time_t now;
70 now = time(NULL);
71 StrEscAppend(Target, NULL, asctime(localtime(&now)), 0, 0);
73 void tmplput_nowno(StrBuf *Target, WCTemplputParams *TP)
75 time_t now;
76 now = time(NULL);
77 StrBufAppendPrintf(Target, "%ld", now);
80 void
81 InitModule_DATE
82 (void)
84 RegisterNamespace("DATE:NOW:STR", 0, 0, tmplput_nowstr, CTX_NONE);
85 RegisterNamespace("DATE:NOW:NO", 0, 0, tmplput_nowno, CTX_NONE);
88 /*@}*/