Files
jq/tests/optional.test
itchyny fd25c3e720 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.
2026-10-08 08:24:10 +09:00

16 lines
332 B
Plaintext

# See tests/jq.test and the jq manual for more information.
# %e is not available on mingw/WIN32
strftime("%A, %B %e, %Y")
1435677542.822351
"Tuesday, June 30, 2015"
# Timestamps before the epoch are not supported on mingw/WIN32
gmtime
-1.25
[1969,11,31,23,59,58.75,3,364]
map(gmtime) | . == sort
[-1.5,-1,-0.5,0,0.5,1,1.5]
true