Skip to content

fix(customParseFormat): correct meridiem parsing for non-English locales#3129

Open
sukvvon wants to merge 1 commit into
iamkun:devfrom
sukvvon:fix/custom-parse-format-meridiem-locale
Open

fix(customParseFormat): correct meridiem parsing for non-English locales#3129
sukvvon wants to merge 1 commit into
iamkun:devfrom
sukvvon:fix/custom-parse-format-meridiem-locale

Conversation

@sukvvon

@sukvvon sukvvon commented Jun 15, 2026

Copy link
Copy Markdown

Description

customParseFormat's meridiemMatch misread PM strings as AM for locales that define a meridiem function (e.g. ko 오전/오후), causing strict-mode parsing to fail.

The loop iterated 1..24 and decided AM/PM with i > 12. Because dayjs uses a 12-hour clock, the PM string first matched at i = 12, where 12 > 12 is false, so it was treated as AM and strict parsing returned Invalid Date.

This changes the loop to iterate 0..23 and decide with i >= 12. The indexOf match is kept intact: with CJK formats such as YYYY年M月D日A... the literal separators bleed into the A token (the parser receives "年月日晚上"), so the partial match is required and the existing zh-cn behavior is preserved.

Fixes #2031

Before

dayjs('2024-01-01 01:00 오후', 'YYYY-MM-DD hh:mm A', 'ko', true).isValid()
// => false (should be 13:00)

After

dayjs('2024-01-01 01:00 오후', 'YYYY-MM-DD hh:mm A', 'ko', true).hour()
// => 13

Tests

Added strict-mode ko meridiem cases (AM, PM, noon, midnight, 11 PM) in test/plugin/customParseFormat.test.js. Full suite passes (778 tests), including existing zh-cn AM/PM cases.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parsing localized time string including meridiem with format 'a hh:mm' ignores meridiem.

1 participant