chrono icon indicating copy to clipboard operation
chrono copied to clipboard

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

Open philppplik opened this issue 1 month ago • 1 comments

Describe the bug

When the day-of-month in a Month D, YYYY date is greater than 31, chrono does not reject the date. Instead the number is treated as a two-digit year and the month is kept, producing a date decades away from anything in the input. With two-digit days the pattern apparently matches the month+year parser, so the real year is dropped entirely.

To Reproduce

const chrono = require("chrono-node"); // 2.10.3

chrono.parseDate("January 32, 2021");  // => 2032-01-01  (expected: null)
chrono.parseDate("May 32, 2021");      // => 2032-05-01  (expected: null)
chrono.parseDate("May 33, 2021");      // => 2033-05-01  (expected: null)
chrono.parseDate("May 99, 2021");      // => 1999-05-01  (expected: null)
chrono.parseDate("32 May 2021");       // => 2021-05-01  (day silently dropped)

For comparison, invalid days that stay within two digits are handled correctly:

chrono.parseDate("February 30, 2021"); // => null (correct)
chrono.parseDate("April 31, 2021");    // => null (correct)
chrono.parseDate("May 0, 2021");       // => null (correct)

So days 32-99 slip through a different parser path than days 30-31 of short months.

Expected behavior

All of these should return null (no result), since no valid date exists in the input.

Environment

  • chrono-node: 2.10.3
  • Node.js: v22.23.3
  • OS: Linux

philppplik avatar Oct 22 '26 04:10 philppplik

Additional data points:

  • chrono.strict handles all of these correctly and returns null.
  • In casual mode, the result for "May 32, 2021" has text === "May 32", start.isCertain("year") === true and start.get("year") === 2032. So the parser claims certainty about a year that contradicts the explicit ", 2021" in the input, which is discarded entirely.

Ideally an explicit 4-digit year in the input would take precedence over the two-digit-year reading of the day component (or the match would fail rather than drop part of the input).

philppplik avatar Oct 22 '26 04:10 philppplik