After a few weeks, working on and off, I’ve almost completely implemented an event calendar that supports repeating events.
In my previous update, I mentioned looking at an iCal implementation (which didn’t meet my needs), as well as finding a forum that laid out the groundwork for implementing recurring events in a database. However, I stumbled upon a much simpler solution:
A pseudo-cronjob implementation (forum link).
From the link above, I would have 3 fields/objects:
events (maps an id to the event name, start time, and array of dates)
event-dates (maps a date to an array of id’s)
*Note: Not yet implemented. Will end up storing a pattern for identifying whether an event falls on a particular day.
For events that have a definite end date (either after a number of occurrences or on a specific date), I enumerate all the dates that event would fall on and add the event ID to the specified date(s) in the map of event-dates.
If I need to delete an event, I would just need to get the ID and iterate over the map, removing the ID wherever found.
If I need to edit an event for a particular day, I would clone the event but give it a different ID, remove the old ID from the event-dates map for that particular day, and add the new event ID.
All that’s left to implement for the calendar is:
- Endless event pattern matching
- Editing / Removing an event
- Modifying the implementation of “ends after x occurrences” to “ends on (date)”
After that, it’s just a short step to implement a checklist displaying what events are happening today. Then I get to play with PhoneGap to try and convert it to an Android / iPhone app.