Description
parseTimeInput (packages/core/src/utils/timeParser.ts) silently mis-parses times written with dotted meridiems: "2:30 p.m." is accepted without error and parsed as 02:30 (AM) instead of 14:30. Worst case, "12 a.m." parses as noon instead of midnight. AP style always writes meridiems with periods, so this is a common way for US users to type times.
Root cause is a drift between four regexes that are supposed to agree. isPM, isAM, and the suffix-strip regex all accept optional dots, but hasMeridiem does not (/[ap]m?\s*$/i). For "2:30 p.m." the suffix is stripped and isPM is true, but hasMeridiem is false, so the 12h-to-24h conversion branch is skipped and the value is treated as a 24-hour time.
Observed on main:
| Input |
Observed |
Expected |
2:30 pm |
14:30 |
14:30 (control, works) |
2:30 p.m. |
02:30 |
14:30 |
12 a.m. |
12:00 |
00:00 |
2 p.m. |
02:00 |
14:00 |
14:30 pm |
null |
null (contradictory input rejected, works) |
14:30 p.m. |
14:30 |
null (dotted variant of the row above should also be rejected) |
parseTimeInput runs on user-typed text committed from TimeInput (blur/Enter) and DateTimeInput, so the field accepts the input with no error and displays a time 12 hours off. Silent wrong data rather than rejection.
Happy to send a PR: derive hasMeridiem from the same regexes as isPM/isAM so the four cannot drift again, with colocated tests for the table above.
Reproduction
- Render a
TimeInput and type 2:30 p.m., then blur
- The field displays 2:30 AM
- Or directly:
parseTimeInput('2:30 p.m.') returns '02:30'; parseTimeInput('12 a.m.') returns '12:00'
XDS Version
@astryxdesign/core@0.1.2 (reproduced on current main)
Environment
Pure string parsing, environment-independent (reproduced in vitest on Windows, Node 22)
Description
parseTimeInput(packages/core/src/utils/timeParser.ts) silently mis-parses times written with dotted meridiems:"2:30 p.m."is accepted without error and parsed as 02:30 (AM) instead of 14:30. Worst case,"12 a.m."parses as noon instead of midnight. AP style always writes meridiems with periods, so this is a common way for US users to type times.Root cause is a drift between four regexes that are supposed to agree.
isPM,isAM, and the suffix-strip regex all accept optional dots, buthasMeridiemdoes not (/[ap]m?\s*$/i). For"2:30 p.m."the suffix is stripped andisPMis true, buthasMeridiemis false, so the 12h-to-24h conversion branch is skipped and the value is treated as a 24-hour time.Observed on main:
2:30 pm14:3014:30(control, works)2:30 p.m.02:3014:3012 a.m.12:0000:002 p.m.02:0014:0014:30 pmnullnull(contradictory input rejected, works)14:30 p.m.14:30null(dotted variant of the row above should also be rejected)parseTimeInputruns on user-typed text committed from TimeInput (blur/Enter) and DateTimeInput, so the field accepts the input with no error and displays a time 12 hours off. Silent wrong data rather than rejection.Happy to send a PR: derive
hasMeridiemfrom the same regexes asisPM/isAMso the four cannot drift again, with colocated tests for the table above.Reproduction
TimeInputand type2:30 p.m., then blurparseTimeInput('2:30 p.m.')returns'02:30';parseTimeInput('12 a.m.')returns'12:00'XDS Version
@astryxdesign/core@0.1.2 (reproduced on current main)
Environment
Pure string parsing, environment-independent (reproduced in vitest on Windows, Node 22)