fix: parse fractional seconds shorter than 3 digits as a decimal fraction - #3167
Open
lenamonj wants to merge 1 commit into
Open
fix: parse fractional seconds shorter than 3 digits as a decimal fraction#3167lenamonj wants to merge 1 commit into
lenamonj wants to merge 1 commit into
Conversation
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.
REGEX_PARSEcaptures fractional seconds as bare digits andparseDatetruncates them with
substring(0, 3)without right-padding, so a fractionshorter than three digits is read as an integer count of milliseconds:
ISO 8601 fractional seconds are a decimal fraction. Strings with a trailing
Zalready take the nativeDatepath and are unaffected; only the regexpath is hit.
Fix: right-pad the capture to three digits before truncating. Fractions of
three or more digits are unchanged (
.999999999still parses as999), andthe no-fraction path still yields
0.Test: one new case in
test/parse.test.jsbeside the existingparses unlimited millisecondtest, comparingvalueOf()andmillisecond()against moment for 1-, 2-, and 3-digit fractions. Withoutthe fix it fails (1 failed, 26 passed in the file); with it the file is 27
passed and the full suite is 774 passed across 93 suites, line coverage
unchanged at 100%.