Files
jq/src/iso8601.h
T
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

15 lines
365 B
C

#ifndef JQ_ISO8601_H
#define JQ_ISO8601_H
#include <stddef.h>
/*
* Parses [buf, buf + len) as an ISO 8601 date and time of day.
*
* On success stores the number of seconds since the Unix epoch in *out and
* returns 1. On failure returns 0 and leaves *out untouched.
*/
int iso8601_parse(const char *buf, size_t len, double *out);
#endif /* JQ_ISO8601_H */