What's the best way to model recurring events in a calendar application? What's the best way to model recurring events in a calendar application? ruby ruby

What's the best way to model recurring events in a calendar application?


I would use a 'link' concept for all future recurring events. They are dynamically displayed in the calendar and link back to a single reference object. When events have taken place the link is broken and the event becomes a standalone instance. If you attempt to edit a recurring event then prompt to change all future items (i.e. change single linked reference) or change just that instance (in which case convert this to a standalone instance and then make change). The latter cased is slightly problematic as you need to keep track in your recurring list of all future events that were converted to single instance. But, this is entirely do-able.

So, in essence, have 2 classes of events - single instances and recurring events.


I have developed multiple calendar-based applications, and also authored a set of reusable JavaScript calendar components that support recurrence. I wrote up an overview of how to design for recurrence that might be helpful to someone. While there are a few bits that are specific to the library I wrote, the vast majority of the advice offered is general to any calendar implementation.

Some of the key points:

  • Store recurrence using the iCal RRULE format -- that's one wheel you really don't want to reinvent
  • Do NOT store individual recurring event instances as rows in your database! Always store a recurrence pattern.
  • There are many ways to design your event/exception schema, but a basic starting point example is provided
  • All date/time values should be stored in UTC and converted to local for display
  • The end date stored for a recurring event should always be the end date of the recurrence range (or your platform's "max date" if recurring "forever") and the event duration should be stored separately. This is to ensure a sane way of querying for events later. Read the linked article for more details about this.
  • Some discussion around generating event instances and recurrence editing strategies is included

It's a really complicated topic with many, many valid approaches to implementing it. I will say that I've actually implemented recurrence several times successfully, and I would be wary of taking advice on this subject from anyone who hasn't actually done it.