Menu

Handling Time Zones in a Global Event Scheduler
πŸ“°

Handling Time Zones in a Global Event Scheduler

DEV Community: backendΒ·desgh whiteΒ·about 3 hours ago
#5Y2Wbl76
#devtobackend#devto#dev#next#event
Reading 0:00
15s threshold

A scheduler that works in UTC and converts only at display time is the standard advice. It is also wrong for a subset of cases: recurring events that the user intends to happen at a local time regardless of DST shifts.

Store the intent, not the instant

For a one-off event, store a UTC timestamp. For a recurring event, store the local time plus the IANA zone:

interface RecurringEvent { localTime : string ; // "14:30" tz : string ; // "Australia/Sydney" rrule : string ; // "FREQ=DAILY" }

Enter fullscreen mode

Exit fullscreen mode

When computing the next occurrence, resolve localTime in the given zone at that future date β€” not today's offset:

import { DateTime } from 'luxon' ;

function nextOccurrence ( event : RecurringEvent ) : DateTime { const now = DateTime . now ( ) . setZone ( event . tz ) ; let next = now . set ( { hour : 14 , minute : 30 , second : 0 } ) ; if ( next <= now ) next = next .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.