Scale ISO 8601 duration fractions by their digit count - #993
Open
ckarnell wants to merge 1 commit into
Open
Conversation
The pure-Python parser divided the fractional part by 10 regardless of length, so P1.25D read as 1 day plus 60 hours. Only single-digit fractions were correct, and the four components shared the assumption.
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.
The pure-Python ISO 8601 parser divides a fractional part by 10 whatever its length:
So
"1.25"givesint("25") / 10, which is 2.5 days instead of 0.25.Single-digit fractions are right, which is why
P1.5Dlooks fine and hides it. The same/ 10appears for weeks, days, hours and minutes, so all four scale wrong together.This is the fallback path, reached through
PENDULUM_EXTENSIONS=0or when the extension will not import, so the Rust parser isn't affected and gives the right answers throughout.Dividing by
10 ** len(part)is the whole change. That's it.The tests import
parse_iso8601directly, sinceparsegoes through the extension and would not exercise this.P1.5Dis in the table as a control: it passes either way, so the other four failing on revert is the fix and not the test. Suite is 1843 passing withPENDULUM_EXTENSIONS=0and 1843 with the extension, up from 1838 both ways.