Time Zone Bugs: How to Test Your App Across the World
A meeting appears an hour early for half your users. A daily report runs twice on one Sunday a year. A user in India sees a timestamp that is thirty minutes wrong. Time zone bugs are rarely spotted on a developerโs laptop because the developer lives in one zone. The cure is testing against a varied set of zones on purpose. Here is what makes time zones tricky and how to build a test matrix that catches problems.
Offsets are not always whole hours
It is tempting to assume time zones differ in whole hours. Real offsets break that assumption:
- Asia/Kolkata โ UTC+05:30 all year.
- Asia/Kathmandu โ UTC+05:45.
- Pacific/Chatham โ UTC+12:45 in standard time.
- Pacific/Kiritimati โ UTC+14:00, one of the earliest places to start each new day.
- Australia/Lord_Howe โ shifts by only 30 minutes for daylight saving.
Any code that stores offsets as integers of hours, or rounds them, will fail in these places.
Daylight saving creates missing and repeated times
When clocks spring forward, a local time such as 02:30 may simply not exist that night. When they fall back, an hour happens twice, so 01:30 can refer to two different moments. Scheduled jobs, alarms and โevery day at 2:30โ rules need a clear policy for both cases.
Dates of change also differ: the United States, the European Union and the Southern Hemisphere switch on different dates, and many countries do not use daylight saving at all. Rules change by law from time to time, which is why software relies on the regularly updated IANA time zone database.
Rules that prevent most bugs
- Store moments in UTC. Convert to local time only when displaying.
- Store the zone name, not the offset.
Europe/Lisbonknows its daylight saving rules; โ+01:00โ does not. - Keep future local events as local time plus zone. If a country changes its rules, a meeting at 9:00 local should stay at 9:00 local.
- Use your platformโs time zone library. Never write offset arithmetic by hand.
- Keep the tz data updated on servers and in dependencies.
Build a test matrix with RandNow
The Random Time Zone Generator above gives you a varied set of zones quickly:
- Set How many? anywhere from 1 to 50.
- Press Generate. Each zone appears in Region/City format with its current UTC offset and local time, for example Asia/Dhaka (UTC+06:00 ยท now 10:18 PM).
- Export the list as CSV, JSON or TXT and use it to parameterize your tests.
- Run your scheduling, display and reporting tests once per zone.
The local times are calculated from your deviceโs clock at the moment you generate, so the list also works as a quick world-clock snapshot. Add a few fixed edge cases by hand โ a half-hour zone, a 45-minute zone and one Southern Hemisphere zone โ so they are always covered.
A starter checklist
- Display a timestamp created at 23:30 UTC โ does the date shift correctly east and west?
- Schedule an event during a daylight saving gap and an overlap.
- Run a daily report across the night the clocks change.
- Check a โtodayโ filter for a user in UTC+14 and one in UTCโ10.
- Confirm exported dates use ISO 8601 with an offset or a trailing Z.
Time zones in the interface
Users rarely know their zoneโs official name. Let them pick a familiar city, detect a sensible default from the device, and show the time in their zone next to any event created by someone elsewhere. Writing โ9:00 (Lisbon time)โ prevents more confusion than any amount of backend logic.
Random times of day help fill these cases:
Pro tips
- Run your test suite with the server set to a non-UTC zone at least once.
- Include Asia/Kolkata and Asia/Kathmandu in every time zone test set.
- Log timestamps in UTC with an explicit Z so logs from different servers line up.
- Never assume a day has exactly 24 hours in local time.
Frequently asked questions
What is the IANA time zone database?
It is the public collection of time zone rules that operating systems and programming languages use. It is updated regularly when governments change their clocks.
Why not just store the UTC offset with each date?
An offset records one momentโs difference from UTC but not the rules for other dates, so it cannot tell you what the offset will be after a daylight saving change.
How many time zones are there?
It depends on how you count. The IANA database has several hundred identifiers because it tracks regions whose rules differ now or differed in the past.