Glossary / Time-zone correctness
Time-zone correctness
Time-zone correctness means representing and displaying temporal data according to its real meaning, the relevant time zone, and changing civil-time rules. A time zone is a region’s rule set, not a fixed UTC offset: offsets change with daylight-saving and political decisions. Systems should distinguish instants from local schedules and date-only values, persist enough information to reconstruct intent, and use maintained time-zone databases rather than fixed-offset assumptions.
Core model
- Store instants in UTC or with an explicit offset; display them in the user’s or event’s intended zone.
- For a recurring meeting at 09:00 Europe/Budapest, preserve the IANA zone and local wall-clock rule, not merely the offset observed today.
- An offset such as
+01:00says how one timestamp relates to UTC; it does not identify future or historical regional rules. - Daylight-saving transitions create gaps (local times that never happen) and overlaps (times that happen twice). Scheduling APIs need explicit disambiguation policy.
- JavaScript
Daterepresents an instant but commonly formats through the host local zone unless options specify otherwise.Intl.DateTimeFormatacceptstimeZone. - Database types differ:
timestamp with time zonesemantics vary by engine; document the contract and normalize at service boundaries. - Time-zone databases are updated as governments change rules. Long-lived schedules may need recalculation after tzdata updates.
Failure modes and testing
Avoid storing an appointment as a bare UTC instant if the user intended a recurring local time; avoid storing a local string without zone if it represents a unique event. Test DST boundary dates, zone changes, historical dates, leap days, midnight crossing, and machines configured in different zones. Make UI labels explicit (“your time”, “UTC”, or named zone) and show the zone for cross-region scheduling. Keep server, browser, and database assumptions aligned.
Interview questions
- Why is a UTC offset not a time zone? It is one offset at one moment; a region’s IANA zone contains historical and future rules.
- How model a recurring 9 a.m. meeting? Store local time, recurrence, and named zone, then resolve each occurrence under current zone rules.
- What is an ambiguous local time? A wall-clock time repeated during a backward clock change; the system must choose earlier/later occurrence or request clarification.
- What is a nonexistent local time? A wall-clock time skipped during a forward transition; define whether to shift, reject, or ask the user.
- How test time-dependent code? Inject a clock, pin zones, test DST boundaries, and avoid dependence on the machine’s current zone or date.