Representing complex scheduled reoccurance in a database
Posted
by David Pfeffer
on Stack Overflow
See other posts from Stack Overflow
or by David Pfeffer
Published on 2010-06-13T14:11:00Z
Indexed on
2010/06/13
14:52 UTC
Read the original article
Hit count: 298
I have the interesting problem of representing complex schedule data in a database. As a guideline, I need to be able to represent the entirety of what the iCalendar -- ics
-- format can represent, but in a database. I'm not actually implementing anything relating to ics
, but it gives a good scope of the type of rules I need to be able to model.
I need to allow allow representation of a single event or a reoccurring event based on multiple times per day, days of the week, week of a month, month, year, or some combination of those. For example, the third Thursday in November annually, or the 25th of December annually, or every two weeks starting November 2 and continuing until September 8 the following year.
I don't care about insertion efficiency but query efficiency is critical. The operation I will be doing most often is providing either a single date/time or a date/time range, and trying to determine if the defined schedule matches any part of the date/time range. Other operations can be slower. For example, given January 15, 2010 at 10:00 AM through January 15, 2010 at 11:00 AM, find all schedules that match at least part of that time. (i.e. a schedule that covers 10:30 - 11:00 still matches.)
Any suggestions? I looked at http://stackoverflow.com/questions/1016170/how-would-one-represent-scheduled-events-in-an-rdbms but it doesn't cover the scope of the type of reoccurance rules I'd like to model.
© Stack Overflow or respective owner