fix: parse ISO dates with a year before 1000 - #85
Open
Osamaali313 wants to merge 1 commit into
Open
Conversation
The `four` helper — named "four" and documented "leading zero string of 4 digits" — padded to 2 instead of 4. It is used only in parse() to build the ISO string handed to `new Date()`, so a valid zero-padded year like "0087" produced "87-06-15T…", which is not valid ISO 8601 and made new Date() return Invalid Date, so parse() threw on a perfectly valid input. Pad to 4 as the name/docs intend. This is a no-op for years >= 1000 (padStart is already satisfied), so existing behavior is unchanged.
|
@Osamaali313 is attempting to deploy a commit to the Formkit Team on Vercel. A member of the Team first needs to authorize it. |
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
parse()throws on a valid, zero-padded ISO date whose year is before 1000:The cause is the
fourhelper insrc/common.ts:It's named
fourand documented "4 digits", but pads to 2. It's used only inparse.tsto assemble the ISO string passed tonew Date():For
Y < 1000,four(Y)yields a 1–3 digit year, so the string (e.g."87-06-15T...") isn't valid ISO 8601,new Date()isInvalid Date, andparse()throws.Fix
Pad to 4, as the helper's name and docstring intend:
This is a no-op for years ≥ 1000 (their string is already ≥ 4 chars, so
padStart(4)andpadStart(2)are identical), so no existing behavior changes. The library already committed to supporting non-4-digit years elsewhere (offset handling, #82); this closes the same gap inparse().Testing
Added a regression test in
parse.spec.ts(parses an ISO date whose year is before 1000). Before the fix it throws; after, it returns the correct date. The fullparsesuite passes (33/33) and the fix leaves every other test unchanged.