@@ -493,6 +493,12 @@ static int match_alpha(const char *date, struct tm *tm, int *offset)
return 2;
}
+ /* ISO-8601 allows yyyymmDD'T'HHMMSS, with less precision */
+ if (*date == 'T' && isdigit(date[1])) {
+ tm->tm_hour = tm->tm_min = tm->tm_sec = 0;
+ return strlen("T");
+ }
+
/* BAD CRAP */
return skip_alpha(date);
}
@@ -639,15 +645,14 @@ static inline int nodate(struct tm *tm)
}
/*
- * Have we filled in any part of the time yet?
- * We just do a binary 'and' to see if the sign bit
- * is set in all the values.
+ * Have we seen an ISO-8601-alike date, i.e. 20220101T0,
+ * In those special case, those fields have been set to 0
*/
-static inline int notime(struct tm *tm)
+static inline int maybeiso8601(struct tm *tm)
{
- return (tm->tm_hour &
- tm->tm_min &
- tm->tm_sec) < 0;
+ return tm->tm_hour == 0 &&
+ tm->tm_min == 0 &&
+ tm->tm_sec == 0;
}
/*
@@ -704,7 +709,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
/* 4 digits, compact style of ISO-8601's time: HHMM */
/* 2 digits, compact style of ISO-8601's time: HH */
if (n == 8 || n == 6 ||
- (!nodate(tm) && notime(tm) &&
+ (!nodate(tm) && maybeiso8601(tm) &&
(n == 4 || n == 2))) {
unsigned int num1 = num / 10000;
unsigned int num2 = (num % 10000) / 100;
@@ -93,7 +93,8 @@ check_parse '20080214T20:30' '2008-02-14 20:30:00 +0000'
check_parse '20080214T20' '2008-02-14 20:00:00 +0000'
check_parse '20080214T203045' '2008-02-14 20:30:45 +0000'
check_parse '20080214T2030' '2008-02-14 20:30:00 +0000'
-check_parse '20080214T20' '2008-02-14 20:00:00 +0000'
+check_parse '20080214T000000.20' '2008-02-14 00:00:00 +0000'
+check_parse '20080214T00:00:00.20' '2008-02-14 00:00:00 +0000'
check_parse '20080214T203045-04:00' '2008-02-14 20:30:45 -0400'
check_parse '20080214T203045 -04:00' '2008-02-14 20:30:45 -0400'
check_parse '20080214T203045.019-04:00' '2008-02-14 20:30:45 -0400'