views:

211

answers:

2

I'm currently working on an application that allows people to schedule "Shows" for an online radio station.

I want the ability for the user to setup a repeated event, say for example:-

"Manic Monday" show - Every Monday From 9-11 "Mid Month Madness" - Every Second Thursday of the Month "This months new music" - 1st of every month.

What, in your opinion, is the best way to model this (based around an MVC/MTV structure).

Note: I'm actually coding this in Django. But I'm more interested in the theory behind it, rather than specific implementation details.

A: 

I've had a thought that repeated events should be generated when the original event is saved, with a new model. This means I'm not doing random processing every time the calendar is loaded (and means I can also, for example, cancel one "Show" in a series) but also means that I have to limit this to a certain time frame, so if someone went say, a year into the future, they wouldn't see these repeated shows. But at some point, they'd have to (potentially) be re-generated.

Mez
You'd normally cancel/change one event in a recurrence using an "exception" event.
Jon Skeet
Hmm.. hadn't thought about that!
Mez
+4  A: 

Ah, repeated events - one of the banes of my life, along with time zones. Calendaring is hard.

You might want to model this in terms of RFC2445. However, that may well give you far more flexibility - and complexity than you really want.

A few things to consider:

  • Do you need any finer granularity than a certain time on given dates? If you need to repeat based on time as well, it becomes trickier.
  • Consider date corner cases such as "the 30th of every month" and what that means for leap years
  • Consider time corner cases such as "1.30am every day" - sometimes 1.30am may happen twice, and sometimes it may not happen at all, due to daylight saving time
  • Do you need to share the schedule with people in other time zones? That makes life trickier again
  • Do you need to represent the number of times an event occurs, or a final date on which it occurs? ("Count" or "until" basically.) You may not need either, or you may need one or both.

I realise this is a list of things to think about more than a definitive answer, but I think it's important to define the parameters of your problem before you try to work out a solution.

Jon Skeet
Some great comments... even if not a definitive answer.
Mez