char * Ns_HttpTime(Ns_DString *pds, time_t *when) { time_t now; char buf[40]; struct tm *tmPtr; if (when == NULL) { now = time(0); when = &now; } tmPtr = ns_gmtime(when); if (tmPtr == NULL) { return NULL; } /* * Provide always english names independent of locale setting. * The format is RFC 1123: "Sun, 06 Nov 1997 09:12:45 GMT" */ snprintf(buf, 40, "%s, %02d %s %04d %02d:%02d:%02d GMT", weekdays_names[tmPtr->tm_wday], tmPtr->tm_mday, month_names[tmPtr->tm_mon], tmPtr->tm_year + 1900, tmPtr->tm_hour, tmPtr->tm_min, tmPtr->tm_sec); Ns_DStringAppend(pds, buf); return pds->string; }
static int StrftimeCmd(ClientData arg,Tcl_Interp *interp, int argc, char **argv) { double d; time_t time; char *fmt, buf[200]; size_t res; int cmd = (int) arg; if (argc != 2 && argc != 3) { Tcl_AppendResult(interp, "wrong # of args: should be \"", argv[0], " ?format? time\"", NULL); return TCL_ERROR; } if (Tcl_GetDouble(interp, argv[argc-1], &d) != TCL_OK) { return TCL_ERROR; } time = (time_t) d; if (argc == 3) { fmt = argv[1]; } else { fmt = cmd == 'f' ? "%c" : "%KC"; } switch (cmd) { case 'f': res = Dci_Strftime(buf, sizeof(buf), fmt, time); break; case 'g': res = strftime(buf, sizeof(buf), fmt, ns_gmtime(&time)); break; default: res = strftime(buf, sizeof(buf), fmt, ns_localtime(&time)); break; } if (res == 0) { Tcl_SetResult(interp, "could not format time", TCL_STATIC); return TCL_ERROR; } Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_OK; }