Skip to content

Validate the month, day and hour ranges of the date-time format - #225

Merged
horejsek merged 1 commit into
horejsek:masterfrom
pcbeingused333:fix/datetime-field-ranges
Oct 20, 2026
Merged

horejsek merged 1 commit into
horejsek:masterfrom
pcbeingused333:fix/datetime-field-ranges

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

The date-time format regex checks the date and time fields with the loose classes [01]\d (month), [0-3]\d (day) and [0-2]\d (hour), and the seconds with [0-5]\d. So it accepts values that cannot be RFC 3339 date-times and rejects one that can:

>>> validate = fastjsonschema.compile({'format': 'date-time'})
>>> validate('2020-19-39T29:00:00Z')   # accepted
>>> validate('1998-12-31T23:59:60Z')   # rejected: RFC 3339 allows the leap second 60

The regex now uses 0[1-9]|1[0-2] for the month, 0[1-9]|[12]\d|3[01] for the day, [01]\d|2[0-3] for the hour (also in the offset), and [0-5]\d|60 for the seconds. The shape of the regex is unchanged: the day is still not checked against the length of the month, and the +hhmm offset form that the existing tests expect stays accepted.

Tests: thirteen rows added to test_datetime in tests/test_format.py (two leap-second values that must be accepted, eleven out-of-range values that must be rejected). Eleven fail on master and all pass with this change; the rest of the suite passes (614 passed, 4 skipped, with tests/benchmarks left out). CHANGELOG.txt has an entry under UNRELEASED.

This change was made with Claude Code.

🤖 Generated with Claude Code

The date-time regex used [01]\d for the month, [0-3]\d for the day and
[0-2]\d for the hour, so values such as 2020-19-39T29:00:00Z were
accepted, while the leap second 23:59:60Z allowed by RFC 3339 was
rejected. Use 01-12, 01-31, 00-23 (also for the offset hours) and
00-60 for the seconds. The day is not checked against the length of the
month, and the +hhmm offset form stays accepted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@horejsek
horejsek merged commit c91ff74 into horejsek:master Oct 20, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants