fix(duration): parse decimal commas in duration strings - #3215
Open
Hugohong258 wants to merge 1 commit into
Open
Hugohong258 wants to merge 1 commit into
Hugohong258 wants to merge 1 commit into
Conversation
lbesecker195
approved these changes
Sep 13, 2026
lbesecker195
left a comment
There was a problem hiding this comment.
DURATION_REGEX_PARSE on dev already accepts [0-9,.] in each component, but Number('1,5') is NaN, so PT1,5S, P1,5Y and PT-1,5S parse to NaN components today. With the replace they become 1.5 / 1.5 / -1.5, matching the point forms. ISO 8601 allows a comma as the decimal sign, and a malformed PT1,5,5S is still NaN either way since only one comma per component is normalized. LGTM.
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.
The duration parser's regular expression already accepts commas in numeric components, but converting those captures directly with
Number()produces NaN. For example,dayjs.duration('PT1,5S').asMilliseconds()returns0instead of1500.Normalize decimal commas to points before converting captured strings to numbers. Add tests for comma/point equivalence across duration units, negative seconds and the normalized ISO output.
Validation: the two new tests fail with the original implementation. After the fix, all 32 duration tests pass, ESLint passes for the changed files, and the full Jest run with coverage passes all 796 tests across 93 suites. The separate multi-time-zone npm script matrix was not run.