-/* Default input handling to save suprising some people */
-
-struct tm *
-date_conv_time(struct tm *tm_time, const char *t_string) {
- int nr;
-
- nr = sscanf(t_string, "%2d%2d%2d%2d%d",
- &(tm_time->tm_mon),
- &(tm_time->tm_mday),
- &(tm_time->tm_hour),
- &(tm_time->tm_min),
- &(tm_time->tm_year));
-
- if(nr < 4 || nr > 5) {
- fprintf(stderr, "date: invalid date `%s'\n", t_string);
- exit( FALSE);
- }
-
- /* correct for century - minor Y2K problem here? */
- if(tm_time->tm_year >= 1900)
- tm_time->tm_year -= 1900;
- /* adjust date */
- tm_time->tm_mon -= 1;
-
- return(tm_time);
-
-}
-
-
-/* The new stuff for LRP */
-
-struct tm *
-date_conv_ftime(struct tm *tm_time, const char *t_string) {
- struct tm itm_time, jtm_time, ktm_time, \
- ltm_time, mtm_time, ntm_time;
-
- itm_time = *tm_time;
- jtm_time = *tm_time;
- ktm_time = *tm_time;
- ltm_time = *tm_time;
- mtm_time = *tm_time;
- ntm_time = *tm_time;
-
- /* Parse input and assign appropriately to tm_time */
-
- if(sscanf(t_string, "%d:%d:%d",
- &itm_time.tm_hour,
- &itm_time.tm_min,
- &itm_time.tm_sec) == 3 ) {
-
- *tm_time = itm_time;
- return(tm_time);
-
- } else if (sscanf(t_string, "%d:%d",
- &jtm_time.tm_hour,
- &jtm_time.tm_min) == 2) {
-
- *tm_time = jtm_time;
- return(tm_time);
-
- } else if (sscanf(t_string, "%d.%d-%d:%d:%d",
- &ktm_time.tm_mon,
- &ktm_time.tm_mday,
- &ktm_time.tm_hour,
- &ktm_time.tm_min,
- &ktm_time.tm_sec) == 5) {
-
- ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
- *tm_time = ktm_time;
- return(tm_time);
-
- } else if (sscanf(t_string, "%d.%d-%d:%d",
- <m_time.tm_mon,
- <m_time.tm_mday,
- <m_time.tm_hour,
- <m_time.tm_min) == 4) {
-
- ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
- *tm_time = ltm_time;
- return(tm_time);
-
- } else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
- &mtm_time.tm_year,
- &mtm_time.tm_mon,
- &mtm_time.tm_mday,
- &mtm_time.tm_hour,
- &mtm_time.tm_min,
- &mtm_time.tm_sec) == 6) {
-
- mtm_time.tm_year -= 1900; /* Adjust years */
- mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
- *tm_time = mtm_time;
- return(tm_time);
-
- } else if (sscanf(t_string, "%d.%d.%d-%d:%d",
- &ntm_time.tm_year,
- &ntm_time.tm_mon,
- &ntm_time.tm_mday,
- &ntm_time.tm_hour,
- &ntm_time.tm_min) == 5) {
- ntm_time.tm_year -= 1900; /* Adjust years */
- ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
- *tm_time = ntm_time;
- return(tm_time);
-
- }
-
- fprintf(stderr, "date: invalid date `%s'\n", t_string);
-
- exit( FALSE);
-
+/* Default input handling to save surprising some people */
+
+/* GNU coreutils 6.9 man page:
+ * date [OPTION]... [+FORMAT]
+ * date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
+ * -d, --date=STRING
+ * display time described by STRING, not `now'
+ * -f, --file=DATEFILE
+ * like --date once for each line of DATEFILE
+ * -r, --reference=FILE
+ * display the last modification time of FILE
+ * -R, --rfc-2822
+ * output date and time in RFC 2822 format.
+ * Example: Mon, 07 Aug 2006 12:34:56 -0600
+ * --rfc-3339=TIMESPEC
+ * output date and time in RFC 3339 format.
+ * TIMESPEC='date', 'seconds', or 'ns'
+ * Date and time components are separated by a single space:
+ * 2006-08-07 12:34:56-06:00
+ * -s, --set=STRING
+ * set time described by STRING
+ * -u, --utc, --universal
+ * print or set Coordinated Universal Time
+ *
+ * Busybox:
+ * long options are not supported
+ * -f is not supported
+ * -I seems to roughly match --rfc-3339, but -I has _optional_ param
+ * (thus "-I seconds" doesn't work, only "-Iseconds"),
+ * and does not support -Ins
+ * -D FMT is a bbox extension for _input_ conversion of -d DATE
+ */
+#include "libbb.h"
+
+enum {
+ OPT_RFC2822 = (1 << 0), /* R */
+ OPT_SET = (1 << 1), /* s */
+ OPT_UTC = (1 << 2), /* u */
+ OPT_DATE = (1 << 3), /* d */
+ OPT_REFERENCE = (1 << 4), /* r */
+ OPT_TIMESPEC = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */
+ OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
+};
+
+static void maybe_set_utc(int opt)
+{
+ if (opt & OPT_UTC)
+ putenv((char*)"TZ=UTC0");