Repository navigation
feat(parser): accept iso 8601 date times without seconds or a zone - #23
Merged
Merged
Conversation
parseRFC3339 only matched a full hh:mm:ss time followed by Z or an
offset. Anything shorter fell through to parseYYYYMMDD, which kept the
date and silently dropped the time ("2026-10-01T12:00Z" read as
midnight), and a zone-less hh:mm:ss consumed its tokens before bailing
out, leaving nothing to parse.
Seconds are now optional and fractional seconds are truncated. Without
Z or an offset the time is local, read the same as "2026-10-01 12:00",
including a trailing zone name. An offset has to be a +/- glued to the
time, so "...T12:00 + 1 hour" stays arithmetic, and the separator has to
be T so "2026-10-01 at 5:30 pm" keeps going through the regular date
path.
Fixes #15
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 16, 2026
aurelleb
marked this pull request as ready for review
November 17, 2026 01:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15
What was wrong
Parser::parseRFC3339()only matched the exact shapeYYYY-MM-DDThh:mm:ssfollowed byZor±hh[:mm]. Anything else fell through toparseYYYYMMDD, which kept the date and silently ignored the rest:2026-10-01T12:00Z(the issue's example)2026-10-01 00:00:00(time dropped)2026-10-01 12:00:00 (Etc/UTC)2026-10-01T12:00+02:00Cannot add DateTime to DateTimeT12:00:00+02:002026-10-01T12:00-05:308 months 1 week 5 days 18 hr 30 minT12:00:00-05:302026-10-01T12:002026-10-01 00:00:00(time dropped)2026-10-01 12:00:00, local2026-10-01T12:00:00Expected EOF, looks like there is nothing we can parse!2026-10-01 12:00:00, local2026-10-01T12:00:00.5Z2026-10-01 00:00:00(time dropped)2026-10-01 12:00:00 (Etc/UTC)The zone-less
hh:mm:sserror came fromparseRFC3339advancing the lexer before checking for a zone, then returningnulloptwith the tokens already consumed.What changed (all inside
parseRFC3339)T12:00Z/T12:00+02:00are read exactly like their:00forms.std::truncbefore the existing range check)..is always a fraction delimiter in the lexer, whatever the locale, so this behaves the same everywhere.Zor offset means local time, read the same as2026-10-01 12:00. A trailing zone name is picked up through the existingparseTimezone(), so2026-10-01T12:00 tokyomatches2026-10-01 12:00 tokyo. TheZand offset branches are unchanged.T(case-insensitive, so the already-working2026-10-01t12:00:00Zkeeps working). Before, any word was accepted. With the looser shape that would have pulled2026-10-01 at 5:30 pminto this path and dropped thepm.+/-glued to the time. Before,parseTimezoneOffset()was always tried, so2026-10-01T12:00:00 + 1 hourread+ 1as UTC+1 (giving13:00 (Etc/UTC+1)and droppinghour). It now gives13:00 (Etc/UTC).Behaviour changes outside the issue's forms
These come from the two checks above. I think they are all improvements, but please look:
2026-10-01T12:00:00 + 1 hour:13:00:00 (Etc/UTC+1)becomes13:00:00local.json(2026-10-01T12:00:00)in a non-UTC zone was treated as UTC, because a glued)reachedparseTimezoneOffset(), which returns offset 0 for any operator. It is now local, likejson(2026-10-01 12:00).2026-10-01 at 12:00:00Z(withatinstead ofT) no longer goes through the RFC path, so theZis ignored as a trailing token and the time is local. That form used to work only because the separator wasn't checked.Not handled (out of scope)
Week dates, ordinal dates, basic format (
20261001T1200Z), hour-only times (T12Z), fractional minutes (T12:00.5Z), and sub-second precision (fractions are truncated, not kept).Things that look off in the existing offset handling (not changed here)
2026-01-18T14:30:00+02:00gives2026-01-18 16:30:00 (Etc/UTC+2). The wall-clock part is treated as UTC and then shown in UTC+2. Under RFC 3339,14:30+02:00is 14:30 local at +2 (12:30 UTC), so it should display14:30:00 (Etc/UTC+2). The existing corpus asserts the current behaviour, so I left it alone and the new no-seconds cases follow it.parseTimezoneOffset()returns an offset of 0 (UTC) for any operator token, not just+/-, without consuming it.parseRFC3339now only calls it after a glued sign, but other callers (utc/gmtinparseTimezone) still behave that way.2026-10-01T12:00:00-2026-...(a glued minus followed by something that isn't a valid hour) consumes the-and yields offset 0. This is unchanged.Tests
tests/corpus/datetime.corpus: added cases for each form above (no seconds withZ/+hh:mm/-hh:mm; no zone with and without seconds; trailing zone name; spaced+ 1 hourwith and without seconds; truncated fractional seconds).tests/datetime.cpp: one new case under Europe/Moscow (UTC+3, no DST) checking that2026-10-01T12:00[:30]is local time. The frozen corpus runs in UTC, where local and UTC can't be told apart.make && ./build/numen-tests: all tests passed (15346 assertions in 94 test cases). The new cases failed before the fix.make debug && ./build-debug/numen-tests(ASan + UBSan): all passed.clang-format --dry-run --Werroris clean on the touched files.NUMEN_USE_DATE_TZ) only. Linux GCC/Clang, MSVC and Nix are left to CI.🤖 Generated with Claude Code