Reject ISO durations with empty time sections - #1012
Open
ZelinZhu-Richard wants to merge 1 commit into
Open
ZelinZhu-Richard wants to merge 1 commit into
ZelinZhu-Richard wants to merge 1 commit into
Conversation
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.
pendulum.parse("PT", strict=True)returns a zero duration, andpendulum.parse("P1DT", strict=True)returns one day, although neither input has a time component afterT.Both parsers accept the separator without requiring a following hours, minutes, or seconds component. Check component presence instead of numeric value so explicit zeros such as
PT0SandP1DT0Sremain valid. Invalid inputs use the existing low-levelValueErrorand publicParserErrorpaths.Addresses the empty-time-section part of #833. Repeated components, long-number parsing, overflow, and duration arithmetic remain outside this change.
Tested separately with the native extension and Python parser:
test_parse_iso8601_duration_invalidandtest_parse_duration_without_time_components: reject empty time sections, includingP1.5DT, where hours derived from a date fraction must not count as a time component.test_parse_iso8601_durationandtest_parse_duration_time_components: preserve explicit zero components and valid date/time combinations.Pull Request Check List
No documentation change is needed for this parser validation fix.
AI assistance: this change was developed with an AI coding tool; I reviewed and tested it.