Back to index

webcit  8.12-dfsg
Functions | Variables
http_datestring.c File Reference
#include "webcit.h"

Go to the source code of this file.

Functions

void http_datestring (char *buf, size_t n, time_t xtime)
 Supplied with a unix timestamp, generate a textual time/date stamp.
void tmplput_nowstr (StrBuf *Target, WCTemplputParams *TP)
void tmplput_nowno (StrBuf *Target, WCTemplputParams *TP)
void InitModule_DATE (void)

Variables

static char * httpdate_months []
 HTTP Months - do not translate - these are not for human consumption.
static char * httpdate_weekdays []
 HTTP Weekdays - do not translate - these are not for human consumption.

Function Documentation

void http_datestring ( char *  buf,
size_t  n,
time_t  xtime 
)

Supplied with a unix timestamp, generate a textual time/date stamp.

Parameters:
bufthe return buffer
nthe size of the buffer
xtimethe time to format as string

Convert "seconds west of GMT" to "hours/minutes offset"

Definition at line 21 of file http_datestring.c.

                                                        {
       struct tm t;

       long offset;
       char offsign;

       localtime_r(&xtime, &t);

#ifdef HAVE_STRUCT_TM_TM_GMTOFF
       offset = t.tm_gmtoff;
#else
       offset = timezone;
#endif
       if (offset > 0) {
              offsign = '+';
       }
       else {
              offset = 0L - offset;
              offsign = '-';
       }
       offset = ( (offset / 3600) * 100 ) + ( offset % 60 );

       snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
              httpdate_weekdays[t.tm_wday],
              t.tm_mday,
              httpdate_months[t.tm_mon],
              t.tm_year + 1900,
              t.tm_hour,
              t.tm_min,
              t.tm_sec,
              offsign, offset
       );
}

Here is the caller graph for this function:

void InitModule_DATE ( void  )

Definition at line 85 of file http_datestring.c.

{
       RegisterNamespace("DATE:NOW:STR", 0, 0, tmplput_nowstr, NULL, CTX_NONE);
       RegisterNamespace("DATE:NOW:NO", 0, 0, tmplput_nowno, NULL, CTX_NONE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tmplput_nowno ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 76 of file http_datestring.c.

{
       time_t now;
       now = time(NULL);
       StrBufAppendPrintf(Target, "%ld", now);
}

Here is the caller graph for this function:

void tmplput_nowstr ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 57 of file http_datestring.c.

{
       char buf[64];
       long bufused;
       time_t now;
       
       now = time(NULL);
#ifdef HAVE_SOLARIS_LOCALTIME_R
       asctime_r(localtime(&now), buf, sizeof(buf));
#else
       asctime_r(localtime(&now), buf);
#endif
       bufused = strlen(buf);
       if ((bufused > 0) && (buf[bufused - 1] == '\n')) {
              buf[bufused - 1] = '\0';
              bufused --;
       }
       StrEscAppend(Target, NULL, buf, 0, 0);
}

Here is the caller graph for this function:


Variable Documentation

char* httpdate_months[] [static]
Initial value:
 {
       "Jan", "Feb", "Mar", "Apr", "May", "Jun",
       "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}

HTTP Months - do not translate - these are not for human consumption.

Definition at line 4 of file http_datestring.c.

char* httpdate_weekdays[] [static]
Initial value:
 {
       "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
}

HTTP Weekdays - do not translate - these are not for human consumption.

Definition at line 10 of file http_datestring.c.