repeating calendar events

From: ben <benc_at_email.arizona.edu>
Date: 21 May 2003 23:24:28 -0700
Message-ID: <71915a6e.0305212224.52145949_at_posting.google.com>



I'm sure this is a common question. I've looked around but couldn't get a satisfactory answer, so here goes.

I am designing a database for a calendar. This can be done in several ways.

Method #1:

The traditional, and easy way of adding events is to add them 1 data at a time. So if I wanted to add "myEvent" all week from 5/21/03 to 5/28/03, I would have to add 7 different events.

a table in this would look like this:

Create Table event(
 date as Date
 event as varchar
}

Method #2:

The next logical step is to make the program do the work. Instead of manually adding 7 events, create a user interface with dropdowns so that the user can select <every> <1> <day> from <5/21/03> to <5/28/03>. The program will then figure out what is needed, and add those 7 records on its own.

This works, but it seems that the database will get overloaded with unecessary data. Also, often people want to schedule an event "every day forever". There is now way that the current design can handle something like this.

Method #3:

So the next step is to just store the data that the user would picked in method #2 directly in the database, so the table would look like this:

create table events(
 start as date //when the repeating records start  end as date //when they end
 intervalType as varchar //day, month, year, etc...  interval as number //every 1,2,3 days ect...  event as varchar
)

So now, one record:

('5/21/03','5/28/03','day',1,'myEvent')

actually represents 7! or better put:

('5/21/03',null,'day',1,'myEvent')

Each record can now represent infinately many records.

Is this a good design? Does anybody know some good sources that talk about problems/solutions related to this kind of thing? Like I said, it seems very common, so I'm sure its been done before.

Some specific problems that I can see:

*What if you want to change only 1 of the 7 records that are derived from the sample record, say, the 3rd one? You would need to create three new records:

('5/21/03','5/22/03','day',1,'myEvent')
('5/23/03','5/23/03','day',1,'myEvent')
('5/24/03','5/28/03','day',1,'myEvent')

This seems messy.

*Also, a more important problem, is that it is impossible to check for scheduling conflicts. If I add a record that repeats every day, and then another one that repeats every week but starts in a month, I have to run the sproc that derives the actual dates and extrapolate both of my entries into the future to see if any of the dates overlap. One problem is that I can't extrapolate to infinity, so I have to choose something like 1 year into the future. This means conflicts can occur 1 year from now. The other, more important problem is if you want to check for confilts when adding to a table, you have to derive the dates for every single row that COULD conflict, which is probobly most of the table. It seems that this sort of operation would take forever.

Thanks for reading this Looong post, I'd really appreciate any feedback anybody can give me.

I'm cross posting this as well.

Thank you,

Ben Received on Thu May 22 2003 - 08:24:28 CEST

Original text of this message