Prompt
What should I use to handle time zones in scheduling?
Latest observation
For scheduling, the safest rule is:
Store and compute in UTC, display in the user’s local time zone, and keep the original time zone/offset when the event is meant to recur.
Practical guidance
-
One-time events:
Store the timestamp in UTC plus the user’s IANA time zone (e.g.America/New_York) if you need to show it back in the original local context. -
Recurring events:
Store the local wall time and the time zone ID separately.
Example: “Every day at 9:00 AM inEurope/London.”
This handles daylight saving changes correctly. -
Never rely only on UTC for recurring schedules
Because “9:00 AM local time” is not the same as a fixed UTC time year-round.
Use IANA time zones
Prefer time zone IDs like:
America/Los_AngelesEurope/BerlinAsia/Tokyo
Avoid fixed offsets like UTC-5 for scheduling logic, because offsets change with daylight saving time.
Tools/libraries
Depending on your stack:
- JavaScript/TypeScript:
Luxon,date-fns-tz, or the built-inIntl.DateTimeFormat - Python:
zoneinfo(built-in in 3.9+), orpytzfor legacy code - Java/Kotlin:
java.time - .NET:
TimeZoneInfo - Ruby:
ActiveSupport::TimeZone
Common pitfalls
- DST gaps and overlaps
- Assuming all days have 24 hours
- Using server local time instead of a named time zone
- Storing only “local time” without a zone
If you want, I can recommend the best approach for your specific language/framework.