Prompt
How do I support time zones and daylight saving time in scheduling?
Latest observation
To support time zones and daylight saving time (DST) in scheduling, the key idea is:
Store and reason about instants in UTC, but collect and display times in the user’s local time zone.
Then handle DST edges explicitly.
Recommended approach
1. Store the right data
For each scheduled event, store:
- The local date and time the user chose (e.g.
2026-03-08 09:00) - The IANA time zone (e.g.
America/New_York) - Optionally the resulting UTC instant for execution/history
Using an IANA time zone ID is important. Don’t store only an offset like -05:00, because offsets change with DST.
2. Convert at the boundaries
- Input: user enters
2026-03-08 09:00inAmerica/New_York - Convert to UTC when saving/executing
- Output: convert from UTC back to the user’s time zone when displaying
3. Use a real time zone database
Use a library that understands DST rules and historical changes:
- JavaScript:
Luxon,date-fns-tz,Temporal(where available) - Python:
zoneinfo - Java/Kotlin:
java.time - C#:
TimeZoneInfo/ Noda Time - Ruby:
tzinfo - Go:
time.LoadLocation
DST pitfalls to handle
Ambiguous times
When clocks go back, one local time occurs twice.
Example:
2026-11-01 01:30inAmerica/New_Yorkmay map to two different UTC instants.
You need a policy:
- Ask the user to choose which occurrence
- Or choose the earlier/later one consistently
- Or require offset selection in edge cases
Non-existent times
When clocks spring forward, some local times do not exist.
Example:
2026-03-08 02:30inAmerica/New_Yorkmay not exist.
You need a policy:
- Reject and ask the user to pick another time
- Or automatically shift to the next valid time
- Or round according to your product rules
Recurring schedules
Recurring events are trickier than one-time events.
For recurring schedules, store:
- The recurrence rule
- The time zone in which recurrence is defined
Then generate each occurrence in that local time zone, because:
- “Every day at 9 AM America/New_York” should stay at 9 AM local time
- The UTC time will change when DST changes
Do not store only a fixed UTC time for recurring local meetings, or they’ll drift by an hour across DST.
Best practices
- Always use IANA zone IDs, not abbreviations like
ESTorPDT - Keep UTC for execution and storage of actual instants
- Keep local time + time zone for human intent and recurrence
- Test DST transition dates explicitly
- Show users the time zone alongside times
- Let users choose their preferred time zone, not just browser/device defaults
Example
User schedules:
- “March 10, 2026 at 9:00 AM in New York”
Store:
local_datetime = 2026-03-10T09:00:00time_zone = America/New_Yorkutc_instant = 2026-03-10T13:00:00Z(depending on DST)
If DST changes later, the same local recurrence rule still means 9 AM New York time.
Practical rule of thumb
- One-time event: store UTC + original zone
- Recurring event: store local time + zone + recurrence rule
- Display: convert UTC to the viewer’s zone
If you want, I can also show:
- a database schema for this, or
- code examples in Python/JavaScript/Java.
Brands