ssquare's avatar

How to handle reoccuring events

I am trying to make booking system something like booking futsal ground. Here, the user can select the time and date and make the book for it, and they can also check for repetition like, daily, weekly, monthly until xx date. This means there will be end-date predefined.

I have searched quite for a few time as some of them are quite complex or some of them are incomplete. What do you recommend to handle such tasks?

Or, if there is any package which handles all of the tasks let me know. Later, I will be integrating with a full calendar, so please consider from that frontend point of view as well.

Update:

So far I have come to the following model after quite some searching:

Events_repeat
--------------------
id
repeat_interval    `1 = daily, 2 = weekly, 3 = monthly`
repeat_date       `this is exactly the date something like 14th of every month`
ordinal        `1 = first, 2 = second, 3 = third, 4 =fourth, 5 = last`
week_days      `1 =  Sunday, 2 =  Monday,  4 = Tuesday, 8 = Wed, 16 = Thu, 32 = Fri, 64 = Sat`
start_date    `start date`
end_date    `end_date`
event_id        `foreign key`

So some examples:

*If occurs daily *

id
1 //daily
0
0
0
2019-05-17
2019-07-17

If occurs weekly

id
2 //weekly
0
0
65   //sun + sat i.e 1+32=33
2019-05-17
2019-07-17

If occurs monthly at 15th of each month

id
3 //monthly
15
0
0
2019-05-17
2019-07-17

If occurs monthly at third Friday of each month

id
3 //monthly
0
3  //third
32  //Friday
2019-05-17
2019-07-17

So, far I am convinced about storing strategy, but I am not convinced yet with its selecting strategy. I could not figure out it yet. How can fetch all the events that are going to happen in a particular month lets say at june of 2019

0 likes
6 replies
devfrey's avatar

I think your post is missing some specifics. What's your current setup? What are the suggestions you've found online?

ssquare's avatar

@devfrey could you check it I have updated the question as per your request adding some details

devfrey's avatar

@SSQUARE - To be honest, it does look like a complex problem. It would probably be possible on the database layer, but I couldn't exactly tell you how. Otherwise, if you're more comfortable doing it in the application itself, you would have to fetch all bookings that have a start date before, and an end date after, the date you want to load events for.

ssquare's avatar

@devfrey do you have any suggestion about how can I design table instead or any third party library or package that handle this for me?

devfrey's avatar

@SSQUARE - Have you considered generating a collection of bookings based on the recurrence rules? It will lead to more records, but if you have the correct table indexes it'll be the fastest and easiest way to go.

Please or to participate in this conversation.