skarim / vobject

A full-featured Python package for parsing and creating iCalendar and vCard files
https://vobject.sameenkarim.com
258 stars 93 forks source link

VObject creates invalid .ics files when using AST timezone #175

Open derelk opened 2 years ago

derelk commented 2 years ago

The following sample code to generate a simple event that spans 2 timezones (AST to EST) seems to create an invalid .ics file. The file cannot be read correctly by the macOS Calendar app, which treats it as a calendar rather than an individual event and will not import the event regardless.

It's also possible that it's an Apple bug, rather than vobject, but I don't understand the VCalendar format well enough to know where the issue is. My guess is it for some reason thinks the end time is before the start time due to the timezone difference, but that isn't true; these timezones are only 1 hour apart for this date, and I even used an assert to confirm that the end time is greater than the start time. Still, if I make the times further apart, it works correctly.

Any idea what's going on here?

macOS Big Sur 11.6.1 Calendar 11.0 Python 3.9.9 vobject 0.9.6.1

from datetime import datetime
from dateutil import zoneinfo

import vobject

if __name__ == '__main__':
    start = datetime(2021, 12, 1, 15, 30, tzinfo=zoneinfo.gettz('America/St_Thomas'))
    end = datetime(2021, 12, 1, 18, 30, tzinfo=zoneinfo.gettz('America/New_York'))
    assert end > start

    cal = vobject.iCalendar()
    event = cal.add('vevent')
    event.add('summary').value = 'Test Event'
    event.add('dtstart').value = start
    event.add('dtend').value = end

    with open('test.ics', 'w') as f:
        cal.serialize(f)
derelk commented 2 years ago

I've learned that if I replace the TZID in DTSTART and DTEND with the timezone name, the .ics file works as expected.

Before (doesn't work):

DTSTART;TZID=AST:20211201T153000
DTEND;TZID=EST:20211201T183000

After (works):

DTSTART;TZID=America/Anguilla:20211201T153000
DTEND;TZID=US/Eastern:20211201T183000