Repository navigation
fix(parsers): accept ISO 8601 fractional seconds longer than 4 digits - #683
Open
CyberNativeAI wants to merge 1 commit into
Open
CyberNativeAI wants to merge 1 commit into
CyberNativeAI wants to merge 1 commit into
Conversation
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.
ISOFormatParseraccepts 1 to 4 digits of fractional seconds. A timestamp with 5 or more digits, such as the 6 that Python'sdatetime.isoformat()writes whenever microseconds are non-zero, does not match the ISO pattern, and other parsers pick up its pieces. There is no error, only a wrong result. On 2.10.3, run withTZ=UTCunless noted:The same happens inside running text ("job finished at 2024-03-10T10:00:00.123456+05:30 with status ok"). Timestamps with no fraction or with 3 digits parse correctly.
The parser's header cites the W3C date/time profile, where the fraction is "one or more digits", and RFC 3339 has
time-secfrac = "." 1*DIGIT.new Date()parses all of the inputs above to the expected instants.Change
PATTERNbecomes\\d+.parseInt(fraction.padEnd(3, "0").slice(0, 3)). Without this line,.123456would be assigned 123456 ms.This millisecond line is the same as the one in open PR 671, which fixes the short-fraction case (
.1read as 1 ms) but keeps the 4-digit limit. So this change also makes.1give 100 ms and.1234give 123 ms; credit for that part goes to PR 671. The two branches merge cleanly in either order and give the same tree.Tests
Three new tests at the end of
test/en/en_inter_std.test.ts, onetest(...)per input: 6 digits with+05:30, 5 digits with-05:00, and 9 digits withZ.TZ=UTC npx jest --ci: without the parser change only the three new tests fail (753 passed, 3 failed); with it, 756 passed. Merged with the branch of PR 671: 832 passed.Z,+05:30and-05:00, against aDatereference and a"JST"reference, underTZ=UTCandTZ=America/New_York: 25 of 37 rows wrong on 2.10.3 and none with this change. The 12 rows with no fraction or 3 digits are correct both before and after.prettier --checkis clean on both changed files.Prepared by CyberNative AI LLC, an AI-run company, using AI agents.