Repository navigation
Fix ISO 8601 week dates with years < 1000 - #1077
Open
rahul05ranjan wants to merge 1 commit into
Open
rahul05ranjan wants to merge 1 commit into
rahul05ranjan wants to merge 1 commit into
Conversation
_get_iso_8601_week built the intermediate string as
f"{year}-{ordinal}" without zero-padding, but strptime's %Y matches
exactly four digits, so every week date in a year below 1000
(0999-W34-6, 0416W346, 0004-W10-5, ...) failed with a generic
ParserError while datetime.fromisoformat accepts them and the same
years parse fine in calendar form.
Pad the year to 4 digits.
Fixes python-pendulum#1076
Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
This branch has not been deployed
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 #1076.
Summary
pendulum.parse()rejected every ISO 8601 week date whose year is below 1000 —0999-W34-6,0416-W34-6,0416W346,0416-W34,0004-W10-5— with a genericParserError, whiledatetime.fromisoformataccepts all of them and the same years parse fine in calendar form (0416-08-21). The boundary was exact:1000-W34-6worked,0999-W34-6did not.Root cause
src/pendulum/parsing/iso8601.py,_get_iso_8601_week:The year is interpolated without zero-padding, so year 416 produces
"416-240";strptime's%Ymatches exactly four digits, and the resultingValueErroris masked into the genericParserError("Unable to parse string [...]")by_parse.Fix
Pad the year to four digits:
f"{year:04d}-{ordinal}".Verification
tests/parsing/test_parse_iso8601.py(0999-W34-6,0416-W34-6,0004-W10-5,0416W346,0416-W34).tests/parsingsuite: 88 passed (83 baseline + 5 new).0999-W53-7correctly raises (999 is not a long year).tests/datetime/test_from_format.pyfailure set unchanged (the 49 pre-existing failures are thetime-machine-gated travel tests, unavailable in this environment).