5 /** I like to believe there is a better way to do this. */
6 #define HAVE_STRUCT_TM_TM_GMTOFF
9 /** HTTP Months - do not translate - these are not for human consumption */
10 static char *httpdate_months[] = {
11 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
12 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
15 /** HTTP Weekdays - do not translate - these are not for human consumption */
16 static char *httpdate_weekdays[] = {
17 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
22 * \brief Supplied with a unix timestamp, generate a textual time/date stamp
23 * \param buf the return buffer
24 * \param n the size of the buffer
25 * \param xtime the time to format as string
27 void http_datestring(char *buf, size_t n, time_t xtime) {
33 localtime_r(&xtime, &t);
35 /** Convert "seconds west of GMT" to "hours/minutes offset" */
36 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
48 offset = ((offset / 3600) * 100) + (offset % 60);
50 snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
51 httpdate_weekdays[t.tm_wday],
52 t.tm_mday, httpdate_months[t.tm_mon], t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec, offsign, offset);
56 void tmplput_nowstr(StrBuf * Target, WCTemplputParams * TP) {
62 #ifdef HAVE_SOLARIS_LOCALTIME_R
63 asctime_r(localtime(&now), buf, sizeof(buf));
65 asctime_r(localtime(&now), buf);
67 bufused = strlen(buf);
68 if ((bufused > 0) && (buf[bufused - 1] == '\n')) {
69 buf[bufused - 1] = '\0';
72 StrEscAppend(Target, NULL, buf, 0, 0);
74 void tmplput_nowno(StrBuf * Target, WCTemplputParams * TP) {
77 StrBufAppendPrintf(Target, "%ld", now);
80 void InitModule_DATE(void) {
81 RegisterNamespace("DATE:NOW:STR", 0, 0, tmplput_nowstr, NULL, CTX_NONE);
82 RegisterNamespace("DATE:NOW:NO", 0, 0, tmplput_nowno, NULL, CTX_NONE);