Time, Dates, and Time Zones
Time, dates, and time zones are the rules software uses to describe when something happened and when it should happen. They prevent local clocks, changing daylight-saving rules, and ambiguous date formats from changing the meaning of a record or schedule.
itComputer fundamentals | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic — Time, Dates, and Time Zones
Time data is several different things wearing one trench coat. An instant is a point on the shared timeline: excellent for an audit event, log entry, or payment that has already happened. A local date and time is what a calendar and clock showed in a place. They look similar on a screen, which is how the trouble gets in.
UTC gives systems a shared reference, and Z says a timestamp has zero offset from it. An offset such as +02:00 says how one local clock related to UTC at one moment. It does not promise that the same place will use that difference next season. For that, keep an IANA time zone such as Europe/Rome: a named collection of local-time rules, histories, and daylight-saving changes. The calendar has acquired a small bureaucracy. It did not ask permission.
This matters because a future appointment is not an event that has already happened. Store the appointment's local date, local time, and named zone so the intended wall-clock time survives rule changes. Store a completed event as a canonical UTC instant, then derive display time later. Store a birthday or accounting day as a date, not as midnight wandering around in an arbitrary zone looking for an argument.
The surprise is that a local time can be missing or repeated. When clocks move forward, a local time can never occur. When they move backward, the same clock reading can name two instants. An application must reject, ask, or apply a documented policy. Quietly choosing a different meeting time is not a time-zone feature. It is a scheduling bug with good posture.
The Cheatsheet condenses the value types and storage rules. The Slides show the flow from government rule changes through IANA data to a runtime. The Practice Reference uses Python to inspect an instant, a repeated local time, and a skipped one. The Field Notes covers the operational traps that hide behind otherwise tidy timestamp strings. Start there when a value looks perfectly normal and behaves as though it has joined a calendar rebellion.
Sources
- https://www.iana.org/time-zones
Supports
- The IANA Time Zone Database contains machine-readable code and data for local-time history
- IANA updates the database for political changes to boundaries, offsets, and daylight-saving rules
- Software and operating systems distribute time-zone-data updates to users
- https://data.iana.org/time-zones/tz-link.html
Supports
- IANA database entries represent locations with shared civil-time clocks since 1970
- IANA names are typically organized by region and representative city
- The database records offset history and daylight-saving use
- Government rule changes and downstream update delays affect future local-time behavior
- https://www.iso.org/iso-8601-date-and-time-format.html
Supports
- ISO 8601 presents numeric dates in year-month-day order
- ISO 8601 covers UTC, local time with UTC offset, date-time values, intervals, and recurring intervals
- Ambiguous numeric dates can have different interpretations
- https://www.rfc-editor.org/rfc/rfc3339
Supports
- RFC 3339 defines an Internet profile of ISO 8601 date-time syntax
- UTC improves interoperability when local daylight-saving rules can change
- Numeric offsets are local time minus UTC
- Alphabetic offset labels have caused interoperability problems
- A timestamp uses Z or a numeric offset
- https://www.rfc-editor.org/rfc/rfc9557
Supports
- A time zone maps timestamps to UTC offsets and local time
- Local times near offset changes can map to zero or multiple timestamps
- An offset does not define local-time rules for related timestamps
- Named IANA zones can change as the IANA database records rule changes
- Offset and time-zone information can become inconsistent for future local times
- https://www.iana.org/time-zones/theory
Supports
- The tz database records civil-time history and predicted future rules
- The database partitions locations whose clocks agree after the POSIX epoch
- Future civil-time predictions can change when governments change rules
- Time-zone abbreviations are ambiguous in practice
- https://docs.python.org/3/library/zoneinfo.html
Supports
- Python zoneinfo supports IANA time zones
- Python zoneinfo uses system time-zone data or the tzdata package
- The fold attribute distinguishes ambiguous local times
- https://docs.python.org/3/library/datetime.html
Supports
- Python datetime distinguishes aware and naive objects
- astimezone converts aware datetimes between time zones
- https://tc39.es/proposal-temporal/docs/
Supports
- Temporal provides separate JavaScript date-time value types
- Temporal includes instant and zoned date-time representations
- https://moment.github.io/luxon/
Supports
- Luxon provides JavaScript date-time and zone-aware values
- https://date-fns.org/
Supports
- date-fns provides JavaScript date utility functions
- https://day.js.org/
Supports
- Day.js provides JavaScript date-time utilities and plugins
- https://momentjs.com/docs/
Supports
- Moment.js documents date-time parsing, manipulation, and formatting
- https://www.nodatime.org/
Supports
- Noda Time provides .NET date-time types including instants and time zones
- https://www.joda.org/joda-time/
Supports
- Joda-Time is a Java date-time library used by existing applications
- https://www.iso.org/standard/70907.html
Supports
- ISO 8601 specifies date and time representations
- https://www.rfc-editor.org/rfc/rfc5545
Supports
- RFC 5545 specifies iCalendar objects and time-zone components
- https://www.iana.org/time-zones/releases/data2011j
Supports
- IANA published time-zone database release data2011j in 2011
- https://www.rfc-editor.org/rfc/rfc7808
Supports
- RFC 7808 specifies an HTTP time-zone data distribution service
- https://www.rfc-editor.org/rfc/rfc8536
Supports
- RFC 8536 specifies the Time Zone Information Format
- https://peps.python.org/pep-0615/
Supports
- PEP 615 added the zoneinfo module to Python's standard library
- https://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time
Supports
- Practitioner guidance catalogs common incorrect assumptions about time in software
