Handling recurring events.
Hey all,
So I am working on a new project where users can schedule recurring/one off events in their calendar and after scheduling those dates are open for bookings.
I am researching how to approach the recurrence pattern and I found multiple resources that helped me to clear things a bit. So basically I choose this path:
Create an Event model that will hold the following: Start date End date Duration Recurrence rule/pattern https://www.kanzaki.com/docs/ical/rrule.htm
Create an Event Exception model that will hold the following: Event ID (foreign key) Exception Date
Based on that for each recurring event, generate new event instances that exist between the query start and end dates and match the recurrence pattern (basically clone the event for this range) at runtime (don't store one event per day in the DB). If any event exceptions exclude them from the schedule.
Now for Update/Delete operations we have two options:
- Update/Delete all future instances:
To solve the above: Split the original event in two each with its own distinct recurrence data. The original event is updated with a new end date and recurrence pattern, and the new event is a complete copy of the original (new row in the database) with a different event id and a different start date + recurrence pattern combination.
- Update/Delete single instance
To delete an instance create an event exception.
To update a single instance:
- create an exception entry,
- create a new non-recurring event stored that contains the data unique to that instance.
Now where I am stuck is how to handle bookings on those events. Should I create again a new row in the database and remove it from the original event schedule? Should the booking just hold the date and be linked to the original event?
I would really appreciate any feedback on my approach or if you guys see a more clever way. Seems that it's getting a bit complicated.
Thanks a lot!
Please or to participate in this conversation.