Calendars and recurring events

John Roth johnroth at ameritech.net
Fri Jan 25 14:26:27 EST 2002


"Dave Swegen" <dswegen at software.plasmon.com> wrote in message
news:mailman.1011954759.15321.python-list at python.org...
> I'm about to write a calendar, which I hope will eventually support
> events. Now I know how I'm going to go about most of the task, but the
> one aspect that has me stumped is recurring events.
>
> I'd like the user to be able to specify "repeat once a year", "repeat
> until ddmmyyyy", "repeat every two weeks", "repeat first Monday of the
> month" etc etc.
>
> The only way I can think of doing it is by having an Event class,
which
> contains the details of the recurrence. As Events are created they are
> placed into a list (or possibly a dbm keyed using a unique Event id).
>
> My problem is that any time I want a view of events (say a one month
> view), the program is going to have to traverse the whole list, and
ask
> if that event is due to be repeated for every day in that view. For
one
> month that would be ~30 traversals of the list, which seems disgusting
in
> its innefficiency. It might be possible to mitigate it somewhat by
> cacheing results into a second hash (using the date as the key), but
> that only seems like a small improvement.

That's the hard way of doing it. The last time I did something like that
(setting up the projected schedule in a mainframe shop) the program
did the entire month for one job, then the entire month for the next,
and so forth. The iterator idea proposed sounds real nice for that.
You just call the iterator for the beginning date you want, and then
kill it when it generates a date after your ending.

This way, you only process each event once.

One thing to watch out for: if you allow real complex things, like
"third work day after the last Friday of the month," you may have
to process the previous and next month in order to get everything.

John Roth





More information about the Python-list mailing list