Recurring Event Template

From time to time I come across a feature that would be better if I introduced some repetitive awkwardness into it.

To do this, let me use a famous example. In Google Calendar, when I set an event to be recurring, say every Monday, it will show it every Monday. I can continue to advance the weeks ahead, and he will show this event.

I really do not believe that they create an event in the database every Monday to infinity :-), and they do not create it until some distant year.

I would like to know if there is any well-known model for doing such a thing or any best practice guide.

Thanks.

+8
design-patterns
source share
2 answers

As far as I know, Martin Fowler has a final word on how to describe recurrence in terms of data modeling. After you capture the repetitions, you just need to provide the code to retrieve the events for a given date (time).

+16
source share

This problem has long been dead, but I was looking for an answer; something simple that will handle all the most common approaches. In particular, how to save these dates in a relational database.

I am considering, but have not implemented the following solution:

Table: Schedule

Id

Name

Startdate

Endate

DayOfYear (there can be any sequence of numbers from 1-365)

DayOfMonth (can be any sequence of numbers from 1-31)

Month (any sequence 1-12)

DayOfWeek (Any sequence of 1-7)

WeekOfMonth (any sequence of 1-5)

SkipInterval (smallint)

Exclude (Many2Many relation to this table)

Examples:

Where are all the other meanings: Nil.

Labor Day: StartDate = 9/1/2013, DayOfWeek = 2 (Monday), month = 9, WeekOfMonth = 1

Valentine's Day: StartDate = 2/14/2013, DayOfMonth = 14, Month = 2

Every third Friday of every month: StartDate = 9/20/2013, DayOfWeek = 6, WeekOfMonth = 3

Any other Friday: StartDate = 10/4/2013; DayOfWeek = 6, SkipInterval = 2

Every day of the week: StartDate = 10/4/2013; DayOfWeek = 2-6

Every day: StartDate = 10/4/2013

Every Monday: StartDate = 10/7/2013, DayOfWeek = 2

Exceptions can be used to remove all holidays from the event schedule. (Nobody is going to work for Thanksgiving, right?), Assuming all the Holidays are introduced.

+1
source share

All Articles