Repository navigation
Conversation
Fixes jquense#2339. parseDateStruct() truncated the fractional-seconds capture group to its first 3 characters and read that directly as milliseconds. For a fraction with 3+ digits this is a correct truncation, but for a shorter fraction it's wrong: ".5" (500ms) was read as the literal integer 5, ".05" (50ms) as 5, and ".12" (120ms) as 12. Right-pad the truncated fraction with zeros before parsing it as a number, so it matches the native ISO 8601 parser (`new Date` / `Date.parse`), which parseIsoDate.ts's own header says it enhances.
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
Fixes #2339.
parseDateStruct()insrc/util/parseIsoDate.tstruncates the fractional-seconds capture group to its first 3 characters and reads that directly as milliseconds:For a 3+ digit fraction this is a correct truncation (
.123→123), but for anything shorter it's wrong, because the substring is read as a literal integer rather than a fraction:.5→5instead of500,.05→5instead of50,.12→12instead of120.Fix
Right-pad the truncated fraction with zeros before parsing it as a number (
.substring(0, 3).padEnd(3, '0')), matching the native ISO 8601 parser (new Date/Date.parse) that this file's own header says it enhances. This doesn't change behavior for 3+ digit fractions, whichpadEndleaves untouched.(This is distinct from #60, which fixed the leading-zero case for exactly-3-digit fractions like
.012; that case was already correct and stays correct here.)Test plan
fractional seconds shorter than 3 digitsblock intest/util/parseIsoDate.tscovering.5,.05, and.12, each asserted against both the expectedDate.UTC(...)value andDate.parse(...)directly.yarn vitest run— 873 passing, 2 pre-existing skipped.yarn lintpasses.