Parse the full ISO 8601 grammar in fromdateiso8601 (#3617)

`fromdateiso8601` was `strptime("%Y-%m-%dT%H:%M:%SZ") | mktime`, which
accepts only one of the many representations ISO 8601 permits. strptime
cannot be extended to cover the rest portably, since it has no specifier
for fractional seconds and glibc discards `%G` and `%V`.

Replace it with a parser in src/iso8601.c that handles basic and extended
representations, ordinal and week dates, fractional seconds, offsets and
date-only input. It uses integer arithmetic instead of `time_t`, so the
results no longer depend on the platform.

This is stricter than before. Impossible dates like `2015-02-30`, which
`mktime` used to normalize into March, and unpadded components like
`2015-3-5T6:00:00Z` are now errors. So is any trailing input, including
whitespace. Leading whitespace is rejected too; before, glibc skipped it
and macOS did not. A leap second now maps to the second before it rather
than the next minute. The error message has changed, and the result can
now be non-integer.
This commit is contained in:
itchyny authored and GitHub committed 2026-10-08 08:24:10 +09:00
1 parent a19efdd45d
commit fd25c3e720
10 files changed
+560 -20

No files matched your search

-5
View File
@@ -1,10 +1,5 @@
# See tests/jq.test and the jq manual for more information.
# Regression test for #3276 (fails on mingw/WIN32)
fromdate
"2038-01-19T03:14:08Z"
2147483648
# %e is not available on mingw/WIN32
strftime("%A, %B %e, %Y")
1435677542.822351