Review App

Internet Entrepreneurs Blog

Online calendar: recurring events pseudo-code

May 18th, 2006

I recently needed some help building recurring event functionality into a web calendar I was building for Goodvan and I just couldn’t find what I was looking for online. I came up with a few different ways to do it but in the end decided the following is the best method.

Say you already have a very simple calendar table (called Cal) that has an id, event title, and a date. The next step is to create an identical table for recurring events (let’s call it CalRepeat) with the same fields as Cal. Now we need to add a field to Cal called RepeatID to link the two tables (Cal.RepeatID -> CalRepeat.id).

Now we need a separate form for users to enter recurring events, and I’m assuming you already have a form for adding regular events to Cal. When a user adds a recurring event they will enter how often the event is repeated (once a month, every Sunday, etc.) and when the series ends (it will need to be finite for reasons that will become apparent shortly).

Upon submission your script will first need to add a new entry into CalRepeat. Then using the CalRepeat id, loop your script through all the dates that match the criteria (say the 15th of every month through Jan 2008) and add them as new entries into Cal with RepeatID equal to the CalRepeat id.

Now if you need to edit a single event (say just this month’s meeting was moved to the 16th) you only need to update a single record in Cal. Updating an entire series is almost as easy but you’ll need to have kept track of frequency and end date information to make this work. To update the entire series, first delete all the events with RepeatID equal to the Repeat event in question then add them again using the new criteria.

This is a very general description of making a recurring event calendar and you may still find it challenging to set up the necessary loops for adding multiple events or for storing information about frequency in your CalRepeat table. I hope this article can at least get you started on making your very own online calendar!

Leave a Reply