Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data structure for storing recurring events?

I'm looking for a data structure pattern for storing recurring events, but everything I came up with would result in a high number of special case handling or user input and data retrieval are overly complex. (I get the distinct feeling, that I haven't understand the problem domain well enough to do this.)

How can I store Outlook-style recurring events?

  • Every day at 8am
  • Every first tuesday in a month
  • Every December 1st for three years
  • Every two hours for a week
  • ...
like image 786
Daniel Rikowski Avatar asked Oct 10 '09 14:10

Daniel Rikowski


People also ask

How are recurring events stored in a database?

Add a recurrence domain to the database that supports a number of different values, including “daily”, “weekly”, and “monthly”. Add a recurrence column to the events table that identify how an event recurs. Add a recurrence_dates table that contains a pre-generated list of recurrences for a given date.

What is a recurring event?

A Recurring Event is any event that happens more than once.

Can we create a recurring event in calendar?

Set up a new repeating eventOn your computer, open Google Calendar. Add the event title and any other details. Choose how often you want the event to repeat, and when you want the event that repeats to end. At the top right, click Save.


2 Answers

There are various papers describing data structures and algorithms for this use case. In addition you can see the code or descriptions of open source implementation of crontab and of Quartz (Java) or Quartz.NET (.NET).

This is one such paper

http://portal.acm.org/citation.cfm?id=359763.359801&coll=ACM&dl=ACM&CFID=63647367&CFTOKEN=55814330

For example, cron stores the information like this (* means every, so a * under month means every month)

  .---------------- minute (0 - 59)  |  .------------- hour (0 - 23) |  |  .---------- day of month (1 - 31) |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...  |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat  |  |  |  |  | *  *  *  *  *   There are several special entries, most of which are just shortcuts,  that can be used instead of specifying the full cron entry:  Entry      Description                 Equivalent To @reboot    Run once, at startup.       None @yearly    Run once a year             0 0 1 1 * @annually  (same as @yearly)           0 0 1 1 * @monthly   Run once a month            0 0 1 * * @weekly    Run once a week             0 0 * * 0 @daily     Run once a day              0 0 * * * @midnight  (same as @daily)            0 0 * * * @hourly    Run once an hour            0 * * * *  
like image 176
Vinko Vrsalovic Avatar answered Oct 04 '22 04:10

Vinko Vrsalovic


Support the standard iCalendar Event types

The IETF put some thought into this when they created the Internet Calendaring and Scheduling Core Object Specification, better known as iCalendar.

The specification includes event recurrence.

As an added bonus, your database will be amenable to sharing data with other iCalendar compatible data sources such as Google and Apple calendars.

https://www.rfc-editor.org/rfc/rfc5545

like image 45
Mark Harrison Avatar answered Oct 04 '22 03:10

Mark Harrison