Full answer
text
event_series(id, title, starts_local TIMESTAMP, tz TEXT, duration INTERVAL,
rrule TEXT, until DATE) -- 'FREQ=WEEKLY;BYDAY=TU'
event_exceptions(series_id, original_start, new_start, cancelled BOOLEAN,
PRIMARY KEY (series_id, original_start))Why store local time plus zone: a 10:00 meeting in London stays at 10:00 local across daylight saving changes; storing a fixed UTC time would shift it by an hour twice a year.
Querying a week view:
- Expand rules into occurrences between the view's start and end.
- Apply exceptions (skip cancelled, move rescheduled).
- Convert to the viewer's time zone.
Materialising occurrences into an event_instances table for a rolling window makes availability queries simple SQL, at the cost of regenerating them when the rule changes. Editing "this and following" events splits the series into two.
Key points
- Store the rule, not every occurrence
- Keep local time and time zone
- Exceptions table for changes
- Expand per date range
- Optionally materialise a rolling window
Common mistakes
- Storing recurring events in UTC only
- Generating occurrences forever
Follow-ups
- How would you find free slots for several people?
- How would you edit all future occurrences?
Tips
- Explain the time zone choice