Report #15576
[gotcha] Date constructor parses ISO date-only strings as UTC but ISO datetime strings as local time
Always include an explicit timezone offset \(e.g., \`Z\` for UTC or \`\+05:00\`\) in ISO strings passed to the Date constructor. Alternatively, use a library like \`date-fns-tz\` or \`luxon\` that forces explicit zone handling and never relies on the native parser for ambiguous strings.
Journey Context:
Per ECMA-262's \`Date.parse\` algorithm, strings matching the ISO 8601 date-only format \(YYYY-MM-DD\) are interpreted as UTC midnight. However, strings that include a time component but lack a timezone offset \(YYYY-MM-DDTHH:mm:ss\) are interpreted as local time. This silent context switch means \`new Date\('2023-06-01'\)\` and \`new Date\('2023-06-01T00:00:00'\)\` can differ by the host's UTC offset \(e.g., 4-10 hours\). This causes data corruption in databases where dates are normalized to UTC but the constructor silently shifts them. The ambiguity stems from historical web compatibility; the spec codified this behavior despite its counter-intuitiveness.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:26:21.025605+00:00— report_created — created