How to handle dates that repeat indefinitely

I am implementing a fairly simple calendar on a website using PHP and MySQL. I want to be able to handle dates that repeat indefinitely, and I'm not sure if this is the best way to do it.

For a limited time recurring event, it seems advisable to just add each event in the timeframe to my db table and group them using some form of recursive id.

But when there is no limit to how often the event repeats, is it better

a) put records in db for a specific period of time (e.g. next 2 years) and then check periodically and add new records over time. The problem is that if someone looks 3 years ahead, the event won't show

b) there are actually no entries for every event, but instead, when I check my php code for events over a period of time, calculate if a recurring event occurs within that time period. The problem is that this means that there is not a specific entry for each event, which I see as a pain when I want to associate other information (attendance, etc.) with that event. It seems like it might be a little slower

Have any of these methods tried? If so, how did it come about? Or is there some other dodgy tricky method I'm missing?

+2


a source to share


4 answers


I would take approach b, and if someone adds something to it, I would create a "real" event record.



Edit: How many periodic events are you expecting and what periodic events will there be? (for example: every Monday, every two weeks, etc.)

+1


a source


I would create a single entry for the repeated event. Then, if additional information needs to be added on a specific date, I would create an attachment entry with a link to the recurring event.



+1


a source


Third vote for option B - justification that data should only be requested for a limited period of time (i.e. start and end). For performance reasons, I would suggest that besides storing the date / time of the first occurrence, the number of occurrences and frequency that you also support with the last entry in the database.

FROM.

+1


a source


In my experience, generating duplicate dates and checking if a specific date is in this pattern is not that bad. There are only 365 days a year. 10,000 days for almost 30 years. which means the I / O size is relatively small in a practical scenario.

This library might help (but it's javascript): http://github.com/mooman/recurring_dates

0


a source







All Articles