Shelves / Internationalisation
IN·03
Time, Dates and Time Zones
The difference between an instant and a wall-clock time, and why software needs both: UTC and offsets, the IANA time-zone database and how it changes, daylight-saving gaps and overlaps, what to store for past events, future appointments, all-day dates and recurring schedules, durations versus calendar periods, which "day" a report counts, wire formats, Unix time and leap seconds, monotonic clocks, other calendars and week conventions, and the APIs that get it right; with a lab that breaks a daily cut-off across a DST change in Python and PostgreSQL.
Start here: the cut-off that moved
TiffinBox's New Jersey pilot has a rule: "order by 10:30 for tomorrow's lunch". A developer stored the cut-off as 14:30 UTC, which was 10:30 in New York when the feature shipped in October. The lab replayed it:
| Date | Stored as fixed UTC (14:30) | Stored as (10:30, America/New_York) |
|---|---|---|
| 30 Oct 2026 | 10:30 EDT ✔ | 10:30 EDT = 14:30 UTC |
| 2 Nov 2026 | 09:30 EST ✘ | 10:30 EST = 15:30 UTC |
On 1 November New York left daylight saving time. From then on, the "UTC" rule closed orders an hour early, every day, until someone noticed the complaints.
The same lab found five more traps:
- On 8 March 2026, 02:30 doesn't exist in New York (clocks jump 02:00 → 03:00); a library turned it into 03:30 EDT.
- On 1 November 2026, 01:30 happens twice: first at 05:30 UTC (EDT), then at 06:30 UTC (EST).
- "Same time tomorrow" from 10:30 on 31 October: +24 hours gives 09:30 EST; +1 calendar day gives 10:30 EST.
- An order placed at 20:00 UTC on 4 November was on 5 November in Kolkata (01:30) and on 4 November in New York (15:00). Which day's report counts it?
- "IST" meant +05:30 (India), +01:00 (Irish Standard Time) or +02:00 (Israel), depending on the zone.
And PostgreSQL added its own: timestamptz + interval '1 day' gave 09:30 when the session time zone was Kolkata, and 10:30 when it was New York, because day arithmetic uses the session's zone.
Time is the i18n topic that breaks even single-language products, because every product has users, servers or rules in more than one place, and nearly every place changes its clocks or its rules at some point.
How deep to go
Volume 17 defines six mastery levels. For time:
| Level | What you can do |
|---|---|
| L1 | Store timestamps in UTC and display them in the user's zone |
| L2 | Use a proper date-time library; distinguish dates, times, instants and durations |
| L3 | Explain zones vs offsets, DST gaps and overlaps, and choose what to store for each kind of time |
| L4 | Diagnose off-by-one-hour and off-by-one-day bugs from logs and data |
| L5 | Design scheduling, reporting and billing around time zones and rule changes |
| L6 | Run global scheduling systems, calendars or tz-data distribution |
Two kinds of time
Software deals with two different things that both get called "time":
| Kind | Meaning | Examples | Store as |
|---|---|---|---|
| instant | a point on the universal timeline | an order placed, a payment captured, a log line | UTC timestamp (timestamptz, Instant) |
| civil / local time | what clocks and calendars say in a place | "lunch at 12:30", "cut-off 10:30 New York", a birthday | local date/time plus a zone (or no zone for a date) |
Converting between them needs rules: for a zone, which offset applied at that moment. That's what the time-zone database provides.
UTC, offsets and zones
- UTC (Coordinated Universal Time) is the reference timeline; it has no daylight saving.
- An offset is the difference between local time and UTC at a moment:
+05:30,−05:00. Offsets aren't whole hours everywhere: India +05:30, Nepal +05:45, parts of Australia +09:30 and +10:30, Chatham Islands +12:45. - A time zone is a region that has shared the same clock rules since 1970, named in the IANA tz database as
Area/Location:Asia/Kolkata,America/New_York,Europe/Berlin,Asia/Dubai. A zone records every offset change: DST transitions and law changes.
India uses one zone (Asia/Kolkata, +05:30, no DST). The US has six main zones, most with DST. The UAE is +04:00 with no DST. So TiffinBox's three regions need three zones, one of them with twice-yearly changes.
The tz database changes
Governments change their clocks, sometimes at short notice: countries have abolished DST, moved permanently to summer time, changed zones, or postponed a change weeks before it was due. The IANA database is updated several times a year (releases named like 2025b). Every runtime carries its own copy: the OS (/usr/share/zoneinfo), the JVM, Python's tzdata package where the OS has none, ICU in browsers and Android, and phones (updated via OS or, on Android, Play system updates). After a rule change, devices and servers with stale data compute wrong local times. Copies drift apart even on one machine: on this volume's lab server the OS had tzdata 2026e while Node.js 22's bundled ICU carried 2025b. Keep tzdata updated in containers and runtimes, and prefer computing local times on the server with fresh data for anything that matters (cut-offs, billing).
Abbreviations such as IST, CST and BST are not identifiers: the lab found three meanings of IST. Use zone names for rules and numeric offsets for display of a specific instant.
Daylight saving: gaps and overlaps
On a spring-forward day, clocks jump (02:00 → 03:00 in New York): local times in the gap don't exist. On a fall-back day, clocks repeat an hour (02:00 → 01:00): local times in the overlap happen twice.
| Situation | What a library must decide | Usual default |
|---|---|---|
| nonexistent time (02:30 on 8 March 2026, New York) | shift forward, shift back, or reject | shift forward by the gap: 03:30 EDT (lab) |
| ambiguous time (01:30 on 1 November 2026) | earlier or later offset | the earlier one (Python fold=0: EDT, 05:30 UTC); fold=1 gives EST, 06:30 UTC |
Schedules must choose deliberately. A daily job at 02:30 local will skip one day and maybe run twice on another; run such jobs in UTC, or at a time that never falls in a gap (most zones change between 00:00 and 03:00; Asia and Europe differ), or make them idempotent per local date.
What to store
| Kind of time | Store | Why |
|---|---|---|
| past event (order placed, payment, audit) | instant in UTC (timestamptz) |
it happened once; display converts |
| future event at a local time (delivery slot, appointment, cut-off) | local date-time + IANA zone (and optionally the computed instant, recomputed when tzdata changes) | rules may change before it happens |
| recurring schedule ("weekdays 12:30 in Hyderabad") | local time + zone + recurrence rule (iCalendar RRULE) |
each occurrence is computed locally, so it stays at 12:30 across DST |
| calendar date (birthday, holiday, subscription start, invoice date) | date with no time or zone |
storing midnight UTC shifts it a day for users west of UTC |
| time of day ("kitchen opens 07:00") | time + the place's zone |
|
| duration ("prep takes 45 minutes") | a duration | not tied to a calendar |
| the user's preference | the IANA zone (from the device, editable) | not an offset, which changes with DST |
The dangerous combinations: local time without zone for events (ambiguous forever), and UTC for future local events (wrong after DST or rule changes, as the lab's cut-off showed).
Databases
In PostgreSQL:
timestamptzstores an instant (as UTC internally) and displays it in the session'sTimeZone. The lab inserted the same instant written two ways (20:00+00and01:30+05:30): with session UTC both showed20:00+00; with Kolkata both showed01:30+05:30; with New York both showed15:00−05.timestamp(without time zone) discards the offset: the same two inserts were stored as20:00and01:30, two different values for one moment, and nothing in the database can tell which zone each meant.- Interval arithmetic:
'1 day'follows the calendar in the session zone,'24 hours'is exact. The lab got 09:30 for "+1 day" with a Kolkata session and 10:30 with a New York session. Set the session zone explicitly, or convert withAT TIME ZONEbefore calendar arithmetic.
Use timestamptz for instants, date for dates, and a separate text column for an IANA zone where you need civil time. Set servers and database sessions to UTC so nothing depends on where a server happens to run, and convert explicitly.
MySQL's TIMESTAMP converts to UTC using the session zone and is limited to 2038; DATETIME stores local values without zone. Many ORMs silently convert; check what actually reaches the database.
Arithmetic: durations and periods
There are two kinds of "plus one day":
- A duration is an exact length of elapsed time: 24 hours, 86,400 seconds.
- A period is a calendar amount: 1 day, 1 month. "Plus one month" from 31 January is 28 February (or an error, by library); "plus one day" across a DST change is 23 or 25 hours.
The lab: from 10:30 EDT on 31 October, +24 hours = 09:30 EST; +1 day = 10:30 EST. For "same time tomorrow" (reminders, renewals, cut-offs) use periods in the user's zone. For timeouts, expiries and rate limits use durations.
Differences have the same choice: "how many days until the subscription renews" is a count of local calendar dates, not elapsed seconds divided by 86,400.
Which day is it? Reporting and business days
An instant falls on different dates in different zones. The lab's order at 20:00 UTC on 4 November is a 5 November order in Kolkata and a 4 November order in New York; grouping by UTC date put it in neither Kolkata's nor New York's correct day (the lab's query found 2 orders on 5 November by Kolkata day, 0 by UTC day).
So every daily metric needs a reporting zone:
- per-kitchen operational reports: the kitchen's zone;
- company finance: usually the zone of the legal entity, stated on the report;
- global dashboards: UTC, labelled as such.
Compute with (placed_at AT TIME ZONE 'Asia/Kolkata')::date, and in data warehouses (Volume 21) store both the instant and the local date of the relevant zone, since recomputing in every query is slow and error-prone.
Business calendars add more: India's financial year runs April–March; weekends differ (Friday–Saturday in several Gulf countries, while the UAE moved to Saturday–Sunday in 2022); public holidays vary by state; the first day of the week is Monday in most of Europe and Sunday in the US and India's common usage. CLDR provides week data (Intl.Locale.prototype.getWeekInfo() where supported); holidays need a maintained source.
Formats on the wire and on screen
- APIs: ISO 8601 / RFC 3339 with an offset:
2026-11-05T01:30:00+05:30or2026-11-04T20:00:00Z. For civil times, send the local value and the zone separately:{"cutoff_local": "10:30", "zone": "America/New_York"}. Never send ambiguous formats like05/11/2026(5 November or May 11?). - Unix time counts seconds since 1970-01-01T00:00Z, ignoring leap seconds. 32-bit signed Unix time overflows on 19 January 2038; use 64-bit.
- Leap seconds (27 inserted since 1972; none since 2016, and they're scheduled to be abolished by 2035) are handled by most clouds through smearing: spreading the extra second over hours, so clocks never show 23:59:60.
- Display uses the locale's format (chapter 04):
5 Nov 2026, 12:12 pminen-IN,Nov 5, 2026, 12:12 PMinen-US,05.11.2026, 12:12inde-DE. Show the zone when users might be elsewhere ("10:30 New York time"). Relative time ("in 2 hours") avoids zone confusion for near events.
Clocks in programs
- The wall clock (
System.currentTimeMillis,time.time(),Date.now()) can jump forwards or backwards when NTP corrects it or an admin changes it. Use it for timestamps, not intervals. - A monotonic clock (
System.nanoTime,time.monotonic(),performance.now()) only moves forwards. Use it for timeouts, latencies and rate limits. - Clocks on different machines disagree by milliseconds (NTP) or more; don't order distributed events by wall-clock time alone (Volume 5's logical clocks).
- Inject the clock (
java.time.Clock, anow()function parameter) so tests can run at DST boundaries, month ends and leap days.
Calendars
Most software uses the Gregorian calendar, but users may need others: the Islamic (Hijri) calendar for Ramadan timing in the Gulf, the Indian national calendar (Saka), Hindu lunisolar calendars for festivals, the Hebrew, Persian, Thai Buddhist (year 2569 in 2026) and Japanese era calendars. CLDR and ICU support display in many (Intl.DateTimeFormat('ar-SA-u-ca-islamic')). Store Gregorian dates or instants and convert for display; festival dates (Diwali, Eid) come from published tables, since some depend on observation.
APIs that get it right
| Platform | Use | Avoid |
|---|---|---|
| Java / Kotlin | java.time: Instant, ZonedDateTime, LocalDate, ZoneId, Duration, Period (Android: built in since API 26, desugared before) |
java.util.Date, Calendar, SimpleDateFormat |
| Python | datetime with zoneinfo.ZoneInfo (and the tzdata package where needed); timezone-aware datetimes only |
naive datetimes, pytz's localize quirks in new code |
| JavaScript | Temporal (Temporal.Instant, ZonedDateTime, PlainDate) where the runtime supports it, or a polyfill; Intl.DateTimeFormat for display |
arithmetic on Date, which is an instant with local-zone methods |
| Swift | Date (instant), Calendar with an explicit TimeZone, DateComponents |
assuming Calendar.current is the user's intended zone for server data |
| Go | time.Time with time.LoadLocation |
fixed-offset zones for named places |
Testing: run your test suite with the process time zone set to something unusual (TZ=Asia/Kathmandu, +05:45) and to a DST zone, and add explicit tests for the gap, the overlap, month ends, 29 February and the end of the year.
Common traps
- Storing future local events in UTC.
- Storing local times without zones.
- Using offsets or abbreviations instead of IANA zone names.
- Dates stored as midnight UTC timestamps, shown a day early west of UTC.
- Adding 86,400 seconds for "tomorrow".
- Grouping reports by UTC date for local businesses.
- Stale tzdata in containers, JVMs or devices.
- Measuring durations with the wall clock.
- Ambiguous date formats in APIs, CSVs and file names.
Lab: a cut-off, a gap, an overlap and a report
Setup. Python 3.13 with zoneinfo reading the system's IANA tz database, and PostgreSQL 16.15. The Python script computes the 10:30 New York cut-off two ways across the 1 November 2026 DST change, converts the nonexistent and repeated local times of 8 March and 1 November 2026, compares +24 hours with +1 day, converts one instant to three zones and prints offsets and abbreviations. The PostgreSQL script stores the same instant in timestamptz and timestamp columns, displays them under three session zones, counts "orders on 5 November" by two day definitions, and adds '1 day' and '24 hours' under two session zones. All output is real.
Results: Python
| Test | Result |
|---|---|
| cut-off stored as 14:30 UTC, on 30 Oct | 10:30 EDT local |
| cut-off stored as 14:30 UTC, on 2 Nov | 09:30 EST local |
| cut-off stored as (10:30, America/New_York), on 2 Nov | 10:30 EST = 15:30 UTC |
| 02:30 on 2026-03-08, New York | doesn't exist → 07:30 UTC → 03:30 EDT |
| 01:30 on 2026-11-01, fold=0 | EDT, 05:30 UTC |
| 01:30 on 2026-11-01, fold=1 | EST, 06:30 UTC |
| 10:30 EDT on 31 Oct + 24 hours | 09:30 EST on 1 Nov |
| 10:30 EDT on 31 Oct + 1 calendar day | 10:30 EST on 1 Nov |
| 2026-11-04 20:00 UTC in Kolkata / New York | 11-05 01:30 / 11-04 15:00 |
| offsets | Kolkata +05:30, Kathmandu +05:45 |
| "IST" | Kolkata +05:30, Dublin +01:00, Jerusalem +02:00 |
Results: PostgreSQL
Two rows hold the same instant, written as 2026-11-04 20:00+00 and 2026-11-05 01:30+05:30:
| Session zone | timestamptz (both rows) |
timestamp without zone (rows 1, 2) |
|---|---|---|
| UTC | 2026-11-04 20:00+00 | 2026-11-04 20:00, 2026-11-05 01:30 |
| Asia/Kolkata | 2026-11-05 01:30+05:30 | unchanged |
| America/New_York | 2026-11-04 15:00−05 | unchanged |
| Query | Result |
|---|---|
| orders on 5 Nov by Kolkata date | 2 |
| orders on 5 Nov by UTC date | 0 |
10:30 NY on 31 Oct + '1 day', session Kolkata |
09:30 |
| the same, session New York | 10:30 |
+ '24 hours', either session |
09:30 |
What it shows
- UTC is right for instants and wrong for local rules: the cut-off drifted an hour on the DST change.
- Gaps and overlaps are real inputs, and libraries resolve them by a default you should choose deliberately.
- Durations and calendar periods differ on DST days.
timestampwithout zone loses information: one moment became two different stored values.- PostgreSQL's display and day arithmetic follow the session zone, so a server's or connection pool's setting can change results.
- "Which day" depends on the reporting zone.
Try it yourself
- Write
next_cutoff(now, local_time, zone)that returns the next cut-off instant; test it across both 2026 DST changes and inAsia/Kolkata. - Schedule a cron-style job at 02:30 America/New_York and list the instants it would run from 1 to 10 March and 25 October to 5 November 2026.
- Run your project's tests with
TZ=Asia/Kathmanduand thenTZ=America/St_Johns(−03:30 with DST). What fails? - In a browser, compare
new Date(2026, 2, 8, 2, 30)with aTemporal.ZonedDateTimefor the same local time (polyfill if needed). - Check the tzdata version on your laptop, in a container image you deploy, and in your JVM (
java -XshowSettings:propertiesorZoneInfoFile); are they the same?
Revision sheet: time, dates and time zones
Key ideas
- Instants (a point on the timeline) vs civil times (what clocks say somewhere); converting needs a zone's rules.
- Offset ≠ zone. Use IANA names (
Asia/Kolkata), never abbreviations (IST). - The tz database changes several times a year; keep it current everywhere.
- DST gaps (times that don't exist) and overlaps (times that occur twice); choose the resolution.
- Store: past events as UTC instants; future local events as local time + zone; recurring schedules as local time + zone + rule; dates as dates.
- Durations (24 hours) vs periods (1 day); use periods in the user's zone for "same time tomorrow".
- Daily reports need a named reporting zone.
- ISO 8601 with offsets on the wire; monotonic clocks for intervals; inject the clock in tests.
- PostgreSQL:
timestamptzfor instants; display and day arithmetic follow the session zone.
Numbers to remember
- India +05:30 (no DST), Nepal +05:45, UAE +04:00, New York −05:00/−04:00.
- 2026 US DST: starts 8 March, ends 1 November.
- 2038: 32-bit Unix time overflow.
Glossary
- UTC: the reference timeline, no DST.
- Offset: local time minus UTC at a moment.
- Time zone: a region's rules over time, named in the IANA database.
- DST gap / overlap: skipped / repeated local times.
- Fold: Python's flag picking the first or second of a repeated local time.
- Duration / period: exact elapsed time / calendar amount.
- Monotonic clock: a clock that never goes backwards.
- RRULE: iCalendar recurrence rule.
- Leap-second smearing: spreading a leap second over hours.