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

Discussão em 'Python' iniciado por Stack, Março 6, 2025.

  1. Stack

    Stack Membro Participativo

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

    Continue reading...

Compartilhe esta Página