* Fixed up the "Date:" headers to be RFC822-compliant
[citadel.git] / citadel / genstamp.c
diff --git a/citadel/genstamp.c b/citadel/genstamp.c
new file mode 100644 (file)
index 0000000..b3e910b
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Function to generate RFC822-compliant textual time/date stamp
+ *
+ * $Id$
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#include "genstamp.h"
+
+
+static char *months[] = {
+       "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+       "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+static char *weekdays[] = {
+       "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+};
+
+
+/*
+ * Supplied with a unix timestamp, generate an RFC822-compliant textual
+ * time and date stamp.
+ */
+void generate_rfc822_datestamp(char *buf, time_t xtime) {
+       struct tm *t;
+
+       t = localtime(&xtime);
+
+       sprintf(buf, "%s, %02d %s %04d %02d:%02d:%02d %s",
+               weekdays[t->tm_wday],
+               t->tm_mday,
+               months[t->tm_mon],
+               t->tm_year + 1900,
+               t->tm_hour,
+               t->tm_min,
+               t->tm_sec,
+               tzname[0]
+               );
+}
+