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
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"
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) {
37 localtime_r(&xtime, &t);
39 /** Convert "seconds west of GMT" to "hours/minutes offset" */
40 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
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],
57 httpdate_months[t.tm_mon],
67 void tmplput_nowstr(StrBuf *Target, WCTemplputParams *TP)
71 StrEscAppend(Target, NULL, asctime(localtime(&now)), 0, 0);
73 void tmplput_nowno(StrBuf *Target, WCTemplputParams *TP)
77 StrBufAppendPrintf(Target, "%ld", now);
84 RegisterNamespace("DATE:NOW:STR", 0, 0, tmplput_nowstr, CTX_NONE);
85 RegisterNamespace("DATE:NOW:NO", 0, 0, tmplput_nowno, CTX_NONE);