Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/locales/en/parsers/ENMonthNameParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export default class ENMonthNameParser extends AbstractParserWithWordBoundaryChe
result.start.assign("month", month);

if (match[YEAR_GROUP]) {
// Skip the case where the two-digit "year" is an out-of-range day followed by
// the real year (ex: May 32, 2021)
const nextText = context.text.substring(match.index + match[0].length);
if (/^\d{2}$/.test(match[YEAR_GROUP]) && /^\s*,\s*\d{4}(?!\d)/.test(nextText)) {
return null;
}

const year = parseYear(match[YEAR_GROUP]);
result.start.assign("year", year);
} else {
Expand Down
14 changes: 14 additions & 0 deletions test/en/en_month_name_middle_endian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,17 @@ test("Test - Impossible Dates (Strict Mode)", () => {

testUnexpectedResult(chrono.strict, "February 151998", new Date(2014, 7, 10));
});

test("Test - Impossible Dates (Casual Mode)", () => {
testUnexpectedResult(chrono, "January 32, 2021", new Date(2020, 0, 1));

testUnexpectedResult(chrono, "May 32, 2021", new Date(2020, 0, 1));

testUnexpectedResult(chrono, "May 99, 2021", new Date(2020, 0, 1));

testUnexpectedResult(chrono, "May 33,2021", new Date(2020, 0, 1));

testSingleCase(chrono, "The event is on May 32, 2021 now", new Date(2020, 0, 1), (result) => {
expect(result.text).toBe("now");
});
});