Jump to content

Storing Calendar Events / One-time vs recurring


Jessica

Recommended Posts

I'm designing a system that will have events, both one-time and recurring. Trying to decide on my table structure - at this point I'm thinking two separate tables for the event details (with one parent table holding the basic similar data). 

 

I'm having trouble with finalizing how I want to store everything for the recurring table. The types of appointments would be things like:

 

Every day at noon from START_DATE to END_DATE

3 times per day every day from START_DATE to END_DATE (maybe store these as three seperate events?) - it's very likely a recurring event would often be 2-3 times per day.

mon, wed, fri every week, no end

a set day every month

a set day every year

 

So the fields I'm thinking so far are:

 

start_date DATE (optional)

end_date DATE (optional)

start_time TIME (required) (all events require a time, but if it's a recurring event without an end date it won't have dates)

end_time TIME (required)

repeats_on (optional varchar, possible values like MM-DD)

repeats_every (optional varchar: possible values like "mon,wed,fri" or "daily" or "weekly")

 

 

Any input? I'm off to do some searching for more ideas.

 

 

 

 

OR: Do I use PHP to generate the events for each of the ones with start and end dates, and store them in the regular table (and somehow link them together), and then also generate them for up to a certain amount of time for the others?

Link to comment
Share on other sites

Here is a crazy idea, how about using the same working as a cronjob? The problem is that a DATETIME type has no option to blank out certain value (like month, day, or year) which is what you actually need. And using words like 'recurs' or something like it only makes it harder to query.

 

The database schema would be something like:

events (id, date_start, date_end, ..)
events_dates (event_id, date_id)
dates (id, minute, hour, day, weekday, month, year)
Assuming NULL means * you can construct your queries to find the events that occur today, this week, this month, this year. Things like */3 would have to be resolved to multiple dates. Though I guess https://github.com/mtdowling/cron-expression could help achieve you get those dates.

 

The event would have another field that defines when the event ends. The date start will help you query for any relevant events, date_start is always set (creation date otherwise). When date end is NULL then it is ongoing. The dates table holds how many times it should occure.

 

What do you think?

Edited by ignace
Link to comment
Share on other sites

I like it - that never occurred to me but it makes it a lot clearer. I see a similar thing suggested on stack overflow.

 

I think that would work nicely, especially by making the events be able to have more than one entry on the date/Cron table, I can have a lot more flexibility on the rules too.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.