Report #24261
[gotcha] Date constructor parses date-only strings as UTC but datetime strings as local time
Always include explicit timezone offsets \(Z or ±HH:MM\) in ISO strings; when parsing user input without timezone info, manually construct dates using Date.UTC\(year, month-1, day\) to force UTC, or use a library like date-fns-tz to handle ambiguous strings explicitly.
Journey Context:
Per ECMA-262 \(Date Time String Format\), date-only strings \(YYYY-MM-DD\) are parsed as UTC midnight, while strings with time components but no timezone offset are parsed as local time. This creates a discrepancy of several hours depending on the runtime's offset from UTC, commonly causing 'off-by-one-day' bugs when formatting the date back to a string. Many developers assume JavaScript uses either UTC or local time consistently by default. The fix requires explicit offsets or manual UTC construction, though this adds verbosity. The alternative—always appending 'T00:00:00'—incorrectly shifts to local time, so explicit 'Z' is required.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:07:37.517408+00:00— report_created — created