Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the python icalendar.cal.Timezone class to create an icalendar VTIMEZONE

Can someone give me an example of generating a VTIMEZONE section of an icalendar file using the python icalendar library?

I believe this can be done by using the icalendar.cal.Timezone Component class, but don't yet know exactly how.

Preferably, the resulting portion of the icalendar file would be similar to this exported sample from the Mac OS X ICal program (or be analogous, but still valid icalendar format).

BEGIN:VTIMEZONE
TZID:America/Denver
BEGIN:DAYLIGHT
TZOFFSETFROM:-0700
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
DTSTART:20070311T020000
TZNAME:MDT
TZOFFSETTO:-0600
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0600
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
DTSTART:20071104T020000
TZNAME:MST
TZOFFSETTO:-0700
END:STANDARD
END:VTIMEZONE

So far I have this working code, but it doesn't include the needed STANDARD and DAYLIGHT VTIMEZONE elements.

import icalendar
timezone = icalendar.cal.Timezone()
timezone.add('TZID', 'America/Denver')
timezone.to_ical()
like image 631
Paul D. Eden Avatar asked Nov 12 '12 04:11

Paul D. Eden


1 Answers

Currently it seems not to be possible, at least not with heavy hacking using pytz.

There is an ongoing discussion with fairly recent updates on the corresponding icalendar issue. You can find some hacky code there.

This other icalendar issue seems to be where something will be implemented for the VTIMEZONE->icalendar conversion.

like image 188
Germain Chazot Avatar answered Oct 13 '22 22:10

Germain Chazot