Daylight Saving Time Transitions
You'll learn why daylight saving time (DST) changes break date math and why offset arithmetic is unreliable.
The Spring-Forward, Fall-Back Problem
Daylight Saving Time means that on certain dates, clocks "spring forward" (skip an hour) or "fall back" (repeat an hour). This creates bizarre edge cases where:
- A day might have 23 hours (spring forward)
- A day might have 25 hours (fall back)
- An hour might not exist (2:30 AM never happens on spring-forward day)
- An hour might happen twice (1:30 AM occurs twice on fall-back day)
Why Manual Offset Arithmetic Fails
Imagine you calculate "24 hours from now" by adding 86400000 milliseconds. If a DST transition happens during that period, you'll be off by an hour. Similarly, adding "1 day" might land you at a different clock time than expected because the day wasn't actually 24 hours long.
Analogy: It's like assuming every month has 30 days when calculating due dates. February breaks your math immediately.
The Safe Approach
Always use timezone-aware date libraries (Luxon, date-fns with timezone plugins) that understand DST rules. These libraries know:
- When DST transitions occur for specific timezones
- How to handle the "missing hour" (skip forward)
- How to disambiguate the "repeated hour"
- How to add durations correctly across transitions
Never calculate dates by manually adding offset hours. Let the library handle the complexity of DST rules, which vary by region and change over time.
Key Takeaway: DST transitions cause hours to vanish or repeat—always use timezone-aware libraries for date calculations instead of manual offset math, or your arithmetic will fail twice a year.