-/*
- * Convert from a manual date string (see mdoc(7) and man(7)) into a
- * date according to the stipulated date type.
- */
-time_t
-mandoc_a2time(int flags, const char *p)
+ tm = localtime(&t);
+ if (tm == NULL)
+ return NULL;
+
+ /*
+ * Reserve space:
+ * up to 9 characters for the month (September) + blank
+ * up to 2 characters for the day + comma + blank
+ * 4 characters for the year and a terminating '\0'
+ */
+
+ p = buf = mandoc_malloc(10 + 4 + 4 + 1);
+
+ if ((ssz = strftime(p, 10 + 1, "%B ", tm)) == 0)
+ goto fail;
+ p += (int)ssz;
+
+ /*
+ * The output format is just "%d" here, not "%2d" or "%02d".
+ * That's also the reason why we can't just format the
+ * date as a whole with "%B %e, %Y" or "%B %d, %Y".
+ * Besides, the present approach is less prone to buffer
+ * overflows, in case anybody should ever introduce the bug
+ * of looking at LC_TIME.
+ */
+
+ if ((isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday)) == -1)
+ goto fail;
+ p += isz;
+
+ if (strftime(p, 4 + 1, "%Y", tm) == 0)
+ goto fail;
+ return buf;
+
+fail:
+ free(buf);
+ return NULL;
+}
+
+char *
+mandoc_normdate(struct mparse *parse, char *in, int ln, int pos)