4 /** I like to believe there is a better way to do this. */
5 #define HAVE_STRUCT_TM_TM_GMTOFF
7 /** HTTP Months - do not translate - these are not for human consumption */
8 static char *httpdate_months[] = {
9 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
10 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
13 /** HTTP Weekdays - do not translate - these are not for human consumption */
14 static char *httpdate_weekdays[] = {
15 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
20 * \brief Supplied with a unix timestamp, generate a textual time/date stamp
21 * \param buf the return buffer
22 * \param n the size of the buffer
23 * \param xtime the time to format as string
25 void http_datestring(char *buf, size_t n, time_t xtime) {
31 localtime_r(&xtime, &t);
33 /** Convert "seconds west of GMT" to "hours/minutes offset" */
34 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
46 offset = ( (offset / 3600) * 100 ) + ( offset % 60 );
48 snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
49 httpdate_weekdays[t.tm_wday],
51 httpdate_months[t.tm_mon],
61 void tmplput_nowstr(StrBuf *Target, WCTemplputParams *TP)
68 #ifdef HAVE_SOLARIS_LOCALTIME_R
69 asctime_r(localtime(&now), buf, sizeof(buf));
71 asctime_r(localtime(&now), buf);
73 bufused = strlen(buf);
74 if ((bufused > 0) && (buf[bufused - 1] == '\n')) {
75 buf[bufused - 1] = '\0';
78 StrEscAppend(Target, NULL, buf, 0, 0);
80 void tmplput_nowno(StrBuf *Target, WCTemplputParams *TP)
84 StrBufAppendPrintf(Target, "%ld", now);
91 RegisterNamespace("DATE:NOW:STR", 0, 0, tmplput_nowstr, NULL, CTX_NONE);
92 RegisterNamespace("DATE:NOW:NO", 0, 0, tmplput_nowno, NULL, CTX_NONE);