Prompt
How do I handle daylight saving time in appointment scheduling?
Latest observation
Daylight saving time (DST) is one of the easiest ways to create scheduling bugs. The safest approach is:
1) Store times in UTC, display in local time
- Store all appointment instants in UTC in your database.
- Also store the time zone the appointment belongs to (e.g.
America/New_York), if the appointment is tied to a local region. - Convert to local time only for display and user input.
Why: UTC avoids ambiguity in storage, while the time zone lets you reconstruct the correct local wall time later.
2) Ask users for a time zone
If an appointment is meant to happen at “9:00 AM local time,” you need the zone, not just an offset.
- Use IANA time zones like
Europe/London,America/Los_Angeles - Avoid fixed offsets like
UTC-5because offsets change with DST
3) Be careful with ambiguous and nonexistent local times
DST creates two tricky cases:
Ambiguous time
When clocks go back, the same local time happens twice.
Example: 2026-11-01 01:30 in some US zones may occur twice.
You must decide:
- first occurrence
- second occurrence
Nonexistent time
When clocks spring forward, some local times never happen.
Example: 2026-03-08 02:30 may not exist in some zones.
You should:
- reject the input and ask the user to choose another time, or
- auto-adjust according to a clear rule, but make it explicit
4) Use a time-zone-aware library
Don’t manually calculate DST rules. Use built-in or standard libraries:
- JavaScript:
Intl.DateTimeFormat, Luxon, date-fns-tz, Temporal (where available) - Python:
zoneinfo,pytz(older),dateutil - Java:
java.time - .NET:
TimeZoneInfo, NodaTime
5) Schedule recurring appointments by local wall time
For recurring events like “every Monday at 9 AM,” store the recurrence rule in local time plus zone. Then expand occurrences using the zone’s DST rules. This avoids events drifting by one hour after DST changes.
Example:
- “Every Monday at 9:00 AM America/New_York”
- not “every 7 days from the last UTC timestamp”
6) Define policies for edge cases
Have product rules for:
- nonexistent local times
- ambiguous local times
- how reminders should fire
- whether “9 AM” means wall-clock time or exact 24-hour intervals
7) Test around DST transitions
Create test cases for:
- spring forward day
- fall back day
- scheduling and editing appointments near transitions
- recurring events across DST boundaries
- different time zones
Practical rule of thumb
- One-time appointments: store UTC instant + zone
- Recurring appointments: store recurrence rule in local time + zone
- Display/input: always in the user’s local zone
- Never rely on server local time
If you want, I can show a concrete example in Python, JavaScript, or SQL.