Calendars and recurring events

Emile van Sebille emile at fenx.com
Fri Jan 25 07:45: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.

Consider adding start and end date or times, eg to allow things like "12
weekly sessions starting 12jun02" or
"Modays starting 04Mar02", or my favorite missing feature: "Saturdays
preceeding the 1st or 15th"  ;-)

>
> 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).

Or both... ;-)

>
> 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.
>

Sooner or later, I'm assuming you'll want to fire the events.  How about
a class that keeps an ordered list of events by next occurrence.  This
of course would only have each event once, but if you write an getnext
iterator that pops the next event, and a scheduler that puts it back in
based on it's schedule, you could pass the list once putting each event
in, then run it through getnext and scheduler over the period in
question.


HTH,

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list