Practical

Why Daylight Saving Time Is a Nightmare for Developers

Twice a year, an hour either disappears or happens twice — and a surprising amount of software quietly assumes that can never happen.

Most bugs in software involving daylight saving time come down to one wrong assumption: that every day has exactly 24 hours, and every hour happens exactly once. DST breaks both of those assumptions, on a schedule that varies by country and changes with only a year or two of political notice.

The hour that doesn't exist

When clocks "spring forward," a specific local hour is skipped entirely — in the US, for example, 2:00 AM to 2:59 AM simply doesn't occur on that day. Any code that schedules something for "2:30 AM" on that specific date has to decide what it even means to run at a time that never happened. Some systems silently skip the job; others run it an hour later than intended; a few crash outright on the invalid time value.

The hour that happens twice

"Falling back" is the opposite problem: a local hour repeats, so "1:30 AM" refers to two genuinely different instants, an hour apart, on the same calendar day. Log files are especially prone to this — timestamps that only record local time, without a UTC offset attached, become ambiguous for that one hour every year, and there's no way to recover which occurrence a given log line actually refers to after the fact.

Where this quietly breaks duration math

Calculating "8 hours after 6 PM" sounds trivial, but if a DST transition falls inside that window, the wall-clock arithmetic and the actual elapsed time disagree by an hour. Billing systems, shift-scheduling software, and anything computing "time since" a stored local timestamp are common places this shows up — the code is often technically correct for 363 days a year and wrong for one specific week around the transition, which makes it a nightmare to catch in testing.

The practical fix

Store timestamps in UTC internally, always, and only convert to local time for display. UTC has no daylight saving time and no ambiguous hours — every instant maps to exactly one UTC value, which makes it safe to store, compare, and do arithmetic on. Convert to a local time zone only at the last possible step, when you're actually showing something to a person. If you need to double-check exactly when a specific zone's clocks change this year, the DST Change Tracker calculates it live rather than relying on a table that can go stale.

Related

Related tools & reading