Skip to content

fix(en): don't read an out-of-range day before a year as a two-digit year - #678

Open
XuYui wants to merge 1 commit into
wanasit:masterfrom
XuYui:fix/month-name-two-digit-day-with-year
Open

XuYui wants to merge 1 commit into
wanasit:masterfrom
XuYui:fix/month-name-two-digit-day-with-year

Conversation

@XuYui

@XuYui XuYui commented Oct 22, 2026

Copy link
Copy Markdown

Fixes #677.

ENMonthNameMiddleEndianParser already rejects May 32, 2021 because the day is over 31, but ENMonthNameParser then picks up May 32 on its own, reads 32 as a two-digit year and returns 2032-05-01. The explicit , 2021 is dropped.

chrono.parseDate("May 32, 2021"); // before: 2032-05-01, after: null
chrono.parseDate("May 99, 2021"); // before: 1999-05-01, after: null

ENMonthNameParser now skips a two-digit year when it is directly followed by a comma and a four-digit year. Plain May 99 / Aug 9 96 style inputs are unchanged.

32 May 2021 from the issue still gives May 2021 (the stray number is just not part of the match). I left that alone since it doesn't invent a wrong year, happy to tighten it too if you'd prefer.

Added casual-mode cases next to the existing strict-mode impossible-date tests. npm test passes.

…year

"May 32, 2021" was rejected by ENMonthNameMiddleEndianParser (day > 31),
but ENMonthNameParser then matched "May 32" as month + two-digit year and
returned 2032-05-01, dropping the explicit ", 2021".

Skip the two-digit year in ENMonthNameParser when it is followed by a
comma and a four-digit year.

Fixes wanasit#677

This branch has not been deployed

No deployments
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.

Day-of-month values above 31 in "Month D, YYYY" are silently re-interpreted as a two-digit year

1 participant