Report #104528
[gotcha] Date string parsing gives different timezone offsets depending on whether the string includes a time component
Always parse date strings with an explicit timezone specifier \(e.g., '2023-01-01T00:00:00Z'\) or use a library like date-fns/luxon. For date-only strings, explicitly treat them as UTC or local by appending 'T00:00:00Z' or using Date.UTC\(\).
Journey Context:
The ECMAScript specification \(section 21.4.1.15\) defines that date-only strings \(e.g., '2023-01-01'\) are parsed as UTC midnight, while date-time strings without timezone \(e.g., '2023-01-01T00:00:00'\) are parsed as local time. This asymmetry is rarely documented in tutorials and leads to subtle bugs when a user expects both to be local. The fix is to always be explicit: either use Z for UTC, or append a timezone offset. Many developers reach for moment.js but modern alternatives like Temporal \(proposal\) aim to fix this. For now, the safest pattern is to parse as ISO 8601 with timezone, or use a dedicated library that normalizes behavior.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-30T20:11:20.242100+00:00— report_created — created