Prompt
How do I handle time zones in scheduling?
Latest observation
A good rule for scheduling is:
- Store times in UTC
- Store the user/event time zone separately
- Convert to the user’s local time only for display and input
- Be explicit about daylight saving time (DST)
Practical approach
1) Use UTC internally
When you save an event, keep the canonical moment in UTC.
This avoids ambiguity and makes sorting, comparisons, and backend logic much easier.
Example:
- User selects:
2026-03-10 9:00 AMinAmerica/New_York - Convert and store:
2026-03-10T13:00:00Z
2) Keep the original time zone
Also store the zone ID, such as:
America/New_YorkEurope/LondonAsia/Tokyo
This matters because the same local time can mean different UTC values depending on DST and location.
3) Convert at the edges
- On input: interpret the user’s local time in their selected zone, then convert to UTC
- On output: convert UTC back into the user’s preferred/display zone
4) Use real time zone IDs, not just offsets
Avoid storing only offsets like -05:00. Offsets change with DST.
Use IANA time zone names, because they encode DST rules.
Bad:
UTC-5
Good:
America/New_York
5) Be careful with recurring events
Recurring meetings are tricky.
Example: “Every Monday at 9 AM New York time”
You should usually store:
- recurrence rule
- local time of the recurrence
- time zone
Then compute each occurrence using that zone, because UTC times will shift when DST changes.
6) Handle DST edge cases
Some local times:
- don’t exist when clocks spring forward
- happen twice when clocks fall back
Examples:
2026-03-08 02:30in some US zones may not exist2026-11-01 01:30may be ambiguous
Your system should detect and ask the user to confirm if needed.
Recommended data model
For a scheduled event:
event_idstart_utcend_utctime_zone- optionally
local_start/local_endif helpful for display or recurrence
Frontend tips
- Show times in the user’s current zone by default
- Let users choose a zone when scheduling across regions
- Display zone labels clearly, e.g.
9:00 AM EDTor9:00 AM America/New_York
Backend tips
Use well-supported timezone libraries:
- JavaScript/TypeScript:
luxon,date-fns-tz,Temporal(where available) - Python:
zoneinfo,pytz(older, less preferred) - Java:
java.time - .NET:
TimeZoneInfo, NodaTime - Ruby:
ActiveSupport::TimeZone,tzinfo
Simple rule of thumb
If it’s a point in time, store UTC.
If it’s a local schedule rule, store local time + time zone.
If you want, I can also show:
- a database schema for scheduling with time zones, or
- examples in JavaScript/Python/SQL.