3 /** HTTP Months - do not translate - these are not for human consumption */
4 static char *httpdate_months[] = {
5 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
6 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
9 /** HTTP Weekdays - do not translate - these are not for human consumption */
10 static char *httpdate_weekdays[] = {
11 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
16 * \brief Supplied with a unix timestamp, generate a textual time/date stamp
17 * \param buf the return buffer
18 * \param n the size of the buffer
19 * \param xtime the time to format as string
21 void http_datestring(char *buf, size_t n, time_t xtime) {
27 localtime_r(&xtime, &t);
29 /** Convert "seconds west of GMT" to "hours/minutes offset" */
30 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
42 offset = ( (offset / 3600) * 100 ) + ( offset % 60 );
44 snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
45 httpdate_weekdays[t.tm_wday],
47 httpdate_months[t.tm_mon],
57 void tmplput_nowstr(StrBuf *Target, WCTemplputParams *TP)
64 #ifdef HAVE_SOLARIS_LOCALTIME_R
65 asctime_r(localtime(&now), buf, sizeof(buf));
67 asctime_r(localtime(&now), buf);
69 bufused = strlen(buf);
70 if ((bufused > 0) && (buf[bufused - 1] == '\n')) {
71 buf[bufused - 1] = '\0';
74 StrEscAppend(Target, NULL, buf, 0, 0);
76 void tmplput_nowno(StrBuf *Target, WCTemplputParams *TP)
80 StrBufAppendPrintf(Target, "%ld", now);
87 RegisterNamespace("DATE:NOW:STR", 0, 0, tmplput_nowstr, NULL, CTX_NONE);
88 RegisterNamespace("DATE:NOW:NO", 0, 0, tmplput_nowno, NULL, CTX_NONE);