Getting a list of occurrences for a given vCalendar

142 views Asked by At

I'm trying to use vobject, without success, to get a list of datetime objects for all event occurrences (see the RRULE paramether that sets the event to be repeated daily until a date) for a given vCalendar, which seems to be well-formatted (apparently):

BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:iCalendar-Ruby
VERSION:2.0
BEGIN:VEVENT
DTEND:20110325T200000
DTSTAMP:20110926T135132
DTSTART:20110325T080000
EXDATE:
RRULE:FREQ=DAILY;UNTIL=20110331;INTERVAL=1
SEQUENCE:0
UID:2011-09-26T13:51:32+02:[email protected]
END:VEVENT
END:VCALENDAR

Documentation is not really friendly, and google results are scarce...Any idea or example? (the example can be for vobject or any other library or method).

Thanks!

H.

1

There are 1 answers

0
David Arnold On

The VCALENDAR object, as supplied, is not strictly valid: the EXDATE property must have one or more date-time or date values (see 3.8.5.1. Exception Date-Times).

Despite that, vobject parses the data successfully, ending up with an empty list of exceptions in the VEVENT object.

To get the list of occurrences, try:

>>> s = "BEGIN:VCALENDAR ... END:VCALENDAR"
>>> ical = vobject.readOne(s)
>>> rrule_set = ical.vevent.getrruleset()
>>> print(list(rrule_set))
[datetime.datetime(2011, 3, 25, 8, 0), datetime.datetime(2011, 3, 26, 8, 0), datetime.datetime(2011, 3, 27, 8, 0), datetime.datetime(2011, 3, 28, 8, 0), datetime.datetime(2011, 3, 29, 8, 0), datetime.datetime(2011, 3, 30, 8, 0)]
>>>

If we add a valid EXDATE property value, like

EXDATE:20110327T080000

re-parse the string, and examine the RRULE set again, we get:

>>> list(ical.vevent.getrruleset())
[datetime.datetime(2011, 3, 25, 8, 0), datetime.datetime(2011, 3, 26, 8, 0), datetime.datetime(2011, 3, 28, 8, 0), datetime.datetime(2011, 3, 29, 8, 0), datetime.datetime(2011, 3, 30, 8, 0)]
>>> 

which is correctly missing the 27th March, as requested.