Time zones and calendar pitfalls
In short: Time is treacherous in programming: time zones, daylight saving, leap years and leap seconds cause bugs that only appear at certain moments.
In more detail: The most important rule: always store and calculate in UTC internally, and convert to the user’s time zone only for display. That keeps moments unambiguous and comparable.
In Depth
- Daylight saving: On one day a year a day has 23 hours, on another 25. “Tomorrow, same time” is not always +24 hours.
- Zone names:
Europe/Berlin(IANA name) instead of fixed abbreviations such as “CET”, since rules change. - Formats: ISO 8601 (
2026-10-13T08:00:00Z) is unambiguous and sortable. - Dates without time: A birthday is a calendar day, not a moment. Stored as UTC midnight, it slips to the previous day in other zones.
- Leap year: Check February 29. The rule: divisible by 4, except by 100, unless by 400.
- Unix time: Seconds since January 1, 1970 UTC. 32-bit counters overflow in 2038.
See also: UTF-8 and character encoding