Skip to content

fix(core): parse dotted meridiems in parseTimeInput#3464

Open
arham766 wants to merge 1 commit into
facebook:mainfrom
arham766:fix/timeparser-dotted-meridiem
Open

fix(core): parse dotted meridiems in parseTimeInput#3464
arham766 wants to merge 1 commit into
facebook:mainfrom
arham766:fix/timeparser-dotted-meridiem

Conversation

@arham766

@arham766 arham766 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the fix proposed in #3462. isPM, isAM, and the suffix-strip regex in parseTimeInput all accept optional dots, but hasMeridiem used its own regex without them. For "2:30 p.m." the suffix was stripped and isPM was true, yet hasMeridiem stayed false, so the 12h-to-24h conversion was skipped and the input was silently accepted as 02:30; "12 a.m." parsed as noon. This flowed into TimeInput and DateTimeInput, which commit user-typed text through parseTimeInput on blur/Enter.

Rather than aligning a fourth regex, hasMeridiem is now derived as isPM || 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

  • New parses dotted meridiems (a.m./p.m.) block in timeParser.test.ts: 2:30 p.m. / 2:30 P.M. / 2:30 p.m all parse to 14:30, 12 a.m. to 00:00, 12 p.m. to 12:00, 2 p.m. to 14:00; plus 13:00 p.m. is rejected like 13:00 PM.
  • Full runs of timeParser.test.ts (26), TimeInput.test.tsx (18), and DateTimeInput.test.tsx (48) all pass.
  • node scripts/check-changesets.mjs passes.

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
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

@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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 2, 2026
@arham766

arham766 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@cixzhang when you have a moment: this fixes TimeInput silently accepting dotted meridiems 12 hours off (issue #3462). Small diff, verified against the TimeInput and DateTimeInput suites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] TimeInput/DateTimeInput: dotted meridiems parse 12 hours off ("2:30 p.m." becomes 02:30, "12 a.m." becomes noon)

1 participant