Engineering
Avoiding Timezone Bugs in Software
The classic timezone mistakes developers make and the simple rules that prevent them.
· 6 min read
Timezone bugs are notorious because they often pass tests and only break in production for users in the "wrong" part of the world. A few disciplined rules prevent almost all of them.
Store everything in UTC
Persist all timestamps in UTC and convert to local time only at the moment you display them. Mixing local times in your database is the root of most timezone pain.
Use IANA names, never offsets
Store Europe/London, not "+00:00" or "GMT". Offsets change with daylight saving; the IANA name carries the rules so conversions stay correct across DST boundaries and historical dates.
Beware the DST edge cases
- Some wall-clock times do not exist (the spring-forward hour) or happen twice (the autumn fall-back hour).
- Adding "24 hours" is not the same as "tomorrow at the same time" across a DST change.
- Always test with a half-hour-offset zone like Asia/Kolkata to catch whole-hour assumptions.
Let the platform do the math
Modern environments ship the full IANA database. Use the built-in Intl API or a well-maintained library rather than hand-rolling offset arithmetic.