Skip to content

Reject days that do not exist in the date and date-time formats - #228

Open
pcbeingused333 wants to merge 2 commits into
horejsek:masterfrom
pcbeingused333:fix/calendar-days-date-formats
Open

pcbeingused333 wants to merge 2 commits into
horejsek:masterfrom
pcbeingused333:fix/calendar-days-date-formats

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

The date and date-time formats checked each part's range but not the combination, so 2021-02-29, 2020-02-30 and 2021-04-31 were accepted: day 29 to 31 was allowed in every month.

This adds one calendar-aware DATE_REGEX shared by both formats: days 1 to 31 for January, March, May, July, August, October and December, 1 to 30 for April, June, September and November, 1 to 28 for February, and 02-29 only in a leap year (a year divisible by 4, and by 400 when it is a century year). It stays a regexp, like the other formats, so there is no new import and the generated code is the same shape. The named groups year, month and day of the date regexp were not used anywhere and are gone.

Tests: test_date and test_datetime in tests/test_format.py get cases for non-existent days (including 1900-02-29 and 2100-02-29) and for valid edges (2020-02-29, 2000-02-29, 2400-02-29, 2021-04-30). The new rejection cases fail on master and pass now. The suite gives 636 passed and 4 skipped; the 12 errors are the benchmark tests, which need a fixture that was not installed here.

This change was made with Claude Code.

🤖 Generated with Claude Code

pcbeingused333 and others added 2 commits October 20, 2026 15:07
The date and date-time regexps allowed days 29 to 31 in every month, so
2021-02-29, 2020-02-30 and 2021-04-31 were accepted. The day must now
exist in its month, and 29 February needs a leap year (divisible by 4,
and by 400 for century years).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant