Report #102912
[gotcha] new Date\('2023-02-30'\) returns a valid Date object for March 2, 2023, not an invalid date
Always validate date strings manually or use a library like date-fns or Luxon. Check with isNaN\(date.getTime\(\)\) after construction. For strict parsing, use regex or Intl.DateTimeFormat with formatToParts.
Journey Context:
JavaScript's Date constructor is lenient: it overflows months and days. '2023-02-30' becomes March 2 because Feb 30 doesn't exist. This is per spec \(Date.parse uses implementation-dependent heuristics\). Many developers assume invalid dates throw or return null, but they silently produce a shifted date. The only reliable way to detect invalid dates is to check getTime\(\) for NaN. Libraries like date-fns provide isValid\(\) that handles this.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-09T15:53:22.718777+00:00— report_created — created