Common Time Zone Bugs and How to Avoid Them
By Aravind Jagarlamudi · Updated November 19, 2026 · 4 min read
Time zone bugs are among the most common — and most embarrassing — defects in software. They hide during development, pass every test written in the developer's own time zone, and then surface twice a year when daylight saving time changes, or the first time a customer signs up from India. This guide covers the mistakes that cause most of them and the habits that prevent them.
1. Storing local time without a zone
A value like 2026-03-08 02:30:00 is meaningless on its own. Is that New York? London? And in New York, that particular time doesn't exist — clocks jump from 2:00 to 3:00 AM that night.
Do this instead:
- For moments that have already happened (logs, created-at timestamps, payments), store UTC — a
timestamptzin PostgreSQL, an ISO 8601 string ending inZ, or a Unix timestamp. - For things that will happen in the future at a local time (a 9 AM daily standup, a flight departure), store the local date-time plus an IANA time zone name such as
America/New_York.
2. Converting future events to UTC too early
It's tempting to convert everything to UTC on the way in. But governments change time zone rules, sometimes with only a few weeks' notice. If you converted "9:00 AM in Cairo on 15 July next year" to UTC today and Egypt then changes its daylight saving policy, the stored UTC value will be an hour wrong.
Store future local events as local time plus zone, and compute UTC as late as possible — ideally when the event is about to fire — using an up-to-date time zone database.
3. Using offsets instead of time zones
-05:00 is not the same as America/New_York. The offset is only valid for part of the year. Code that stores a user's "time zone" as a fixed offset will show times an hour off for half the year.
Store the IANA name (Europe/Berlin, Asia/Kolkata), and derive the offset for each specific date with a library.
4. Assuming every day has 24 hours
In zones with daylight saving time, one day a year has 23 hours and another has 25. Code that adds 24 * 60 * 60 * 1000 milliseconds to "move to tomorrow" will land at 11 PM or 1 AM on those days.
Use calendar-aware arithmetic: "add one calendar day in this time zone", not "add 86,400 seconds".
5. Scheduling jobs in the 1–3 AM window
A cron job set for 2:30 AM local time will not run on the night clocks spring forward, and may run twice when they fall back. Schedule batch jobs in UTC, or avoid the changeover window entirely.
6. JavaScript's date parsing surprises
JavaScript's built-in Date has several well-known traps:
new Date('2026-03-08'); // parsed as UTC midnight
new Date('2026-03-08T00:00'); // parsed as LOCAL midnight
new Date(2026, 2, 8); // March 8 — months are zero-based!
A date-only string is treated as UTC, so displaying it with local methods can show the previous day for anyone west of Greenwich. Prefer explicit libraries, Intl.DateTimeFormat with a timeZone option for display, and consider the newer Temporal API where your target browsers support it.
new Intl.DateTimeFormat('en-GB', {
timeZone: 'Asia/Kolkata', dateStyle: 'medium', timeStyle: 'short',
}).format(new Date('2026-03-08T12:00:00Z')); // "8 Mar 2026, 17:30"
7. Testing only in your own time zone
If your laptop and CI servers are in the same zone as you, entire categories of bugs are invisible. Run your test suite with different TZ environment variables:
TZ=Asia/Kolkata npm test
TZ=America/St_Johns npm test # UTC−3:30, half-hour offset
TZ=Pacific/Chatham npm test # UTC+12:45, quarter-hour offset
TZ=Australia/Lord_Howe npm test # 30-minute daylight saving shift
And add explicit test cases for the DST transition dates in at least one northern and one southern hemisphere zone.
8. Letting the time zone database go stale
Operating systems, language runtimes and libraries ship their own copies of the IANA time zone database, which is updated several times a year. A server image that hasn't been updated for years can be wrong for countries that changed their rules since — Mexico, Egypt, Kazakhstan and others have all done so recently. Keep base images and runtime packages up to date.
9. Ambiguous display
Even with perfect storage, showing "3:00" to a user without context invites mistakes. Show the zone when there's any chance of confusion ("3:00 PM IST" or "3:00 PM your time"), use 24-hour time or AM/PM consistently, and for global audiences consider showing a second reference zone.
A checklist
- Past moments stored in UTC
- Future local events stored as local time + IANA zone
- User preferences store an IANA zone name, not an offset
- Date arithmetic uses calendar-aware functions
- Scheduled jobs avoid local 1–3 AM or run in UTC
- Tests run under several
TZvalues, including half-hour zones - Time zone data kept current in servers and containers
Related
Summary
Most time zone bugs come from storing local times without a zone, treating offsets as zones, assuming every day is 24 hours, and testing in only one time zone. Store past moments in UTC, future events as local time plus an IANA zone, use calendar-aware arithmetic, and test under several TZ settings — and the twice-yearly bug reports will largely disappear.