Repository navigation
fix: pad short ISO fractional seconds when parsing milliseconds - #2367
Open
draarivpatel-ui wants to merge 1 commit into
Open
draarivpatel-ui wants to merge 1 commit into
draarivpatel-ui wants to merge 1 commit into
Conversation
Fractional-second components with fewer than three digits were truncated rather than scaled, so ".5" parsed as 5ms instead of 500ms and ".05" as 5ms instead of 50ms. Pad the fraction to three digits on the right before converting to a number, matching the native ISO 8601 parser.
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.
Summary
date().cast()anddate().validate()mis-parse ISO datetimes whose fractional-second component has fewer than three digits. The fraction is truncated to three characters but never right-padded, so the digits are read as a literal integer instead of a scaled fraction:Date.1.05.12.5.123The error is silent and can be up to 495 ms.
Fix
In
src/util/parseIsoDate.ts, right-pad the captured fraction to three digits before converting it to a number:Fractions longer than three digits keep the existing truncation behaviour, and
precisionis untouched.Tests
Added cases for
.5,.05,.12(local) and.5Z(UTC) intest/util/parseIsoDate.ts, each compared against the equivalentnew Date(...)construction.Full suite:
875 passed, 2 skipped. ESLint clean on both changed files.Fixes #2339.