fix(core): parse dotted meridiems in parseTimeInput#3464
Open
arham766 wants to merge 1 commit into
Open
Conversation
isPM, isAM, and the suffix-strip regex all accept optional dots, but hasMeridiem used its own regex without them, so '2:30 p.m.' skipped the 12h to 24h conversion and parsed as 02:30, and '12 a.m.' as noon. Derive hasMeridiem from isPM/isAM so the detection cannot drift again. This also makes '14:30 p.m.' rejected consistently with '14:30 pm'. Fixes facebook#3462
|
@arham766 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
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
Implements the fix proposed in #3462.
isPM,isAM, and the suffix-strip regex inparseTimeInputall accept optional dots, buthasMeridiemused its own regex without them. For"2:30 p.m."the suffix was stripped andisPMwas true, yethasMeridiemstayed false, so the 12h-to-24h conversion was skipped and the input was silently accepted as02:30;"12 a.m."parsed as noon. This flowed into TimeInput and DateTimeInput, which commit user-typed text throughparseTimeInputon blur/Enter.Rather than aligning a fourth regex,
hasMeridiemis now derived asisPM || isAM, so the detection can never drift from the conversion logic again. A side effect that falls out for free:"14:30 p.m."is now rejected exactly like"14:30 pm"already was, instead of being accepted as 14:30.Fixes #3462
Test plan
parses dotted meridiems (a.m./p.m.)block intimeParser.test.ts:2:30 p.m./2:30 P.M./2:30 p.mall parse to14:30,12 a.m.to00:00,12 p.m.to12:00,2 p.m.to14:00; plus13:00 p.m.is rejected like13:00 PM.timeParser.test.ts(26),TimeInput.test.tsx(18), andDateTimeInput.test.tsx(48) all pass.node scripts/check-changesets.mjspasses.