From b32435c51fd5e0eaa73f10420861468613f53e6f Mon Sep 17 00:00:00 2001 From: xxiaoxiong Date: Thu, 28 May 2026 09:50:10 +0800 Subject: [PATCH] fix(isISO8601): pad year to 4 digits in strict validation for years < 1000 When `isISO8601` is called with `strict: true`, the `isValidDate` function extracts the year via `Number()`, which converts leading-zero years like `0001` to `1`. The year is then interpolated directly into the date string passed to `new Date()`, causing ambiguous parsing (e.g. `1-01-13` is interpreted as January 13th 2001 instead of January 13th 0001). This fix pads the year to 4 digits before constructing the date string, preserving correct parsing for all year values. Fixes #2517 --- src/lib/isISO8601.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/isISO8601.js b/src/lib/isISO8601.js index 1f797347d..b3dad9fa8 100644 --- a/src/lib/isISO8601.js +++ b/src/lib/isISO8601.js @@ -27,7 +27,9 @@ const isValidDate = (str) => { const dayString = day ? `0${day}`.slice(-2) : day; // create a date object and compare - const d = new Date(`${year}-${monthString || '01'}-${dayString || '01'}`); + // pad year to 4 digits to avoid Date() parsing ambiguity for years < 1000 + const yearString = `${year}`.padStart(4, '0'); + const d = new Date(`${yearString}-${monthString || '01'}-${dayString || '01'}`); if (month && day) { return d.getUTCFullYear() === year && (d.getUTCMonth() + 1) === month