Skip to content

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

Description

@arham766

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

  1. Render a TimeInput and type 2:30 p.m., then blur
  2. The field displays 2:30 AM
  3. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions