Reputation: 4284
My application parses supplied .ics files and fetches the start and end time of a calendar event in UTC. See example .ics file below.
BEGIN:VCALENDAR BEGIN:VTIMEZONE TZID: BEGIN:STANDARD DTSTART:16010101T020000 TZOFFSETFROM:-0400 TZOFFSETTO:-0500 RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11 END:STANDARD BEGIN:DAYLIGHT DTSTART:16010101T020000 TZOFFSETFROM:-0500 TZOFFSETTO:-0400 RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3 END:DAYLIGHT END:VTIMEZONE BEGIN:VEVENT ORGANIZER;CN=blah:MAILTO:[email protected] DESCRIPTION;LANGUAGE=en-US: RRULE:FREQ=YEARLY;COUNT=30;INTERVAL=1;BYMONTHDAY=9;BYMONTH=4 SUMMARY;LANGUAGE=en-US: This is summary DTSTART;TZID=:20160409T000000 DTEND;TZID=:20160410T000000 UID:f663243d-17f2-424a-a52c RECURRENCE-ID;TZID=:20160409T000000 PRIORITY:5 DTSTAMP:20150701T123848Z TRANSP:OPAQUE STATUS:CONFIRMED SEQUENCE:0 LOCATION;LANGUAGE=en-US: END:VEVENT END:VCALENDAR
I have come across situations where there is no TZID mentioned with DTSTART/DTEND (as in the above .ics file), or the TZID is some random string from which you cannot figure out the timezone.
I think the only way to get timezone info in such situations is to parse the VTIMEZONE block to determine the timezone offset and then apply it to the start and end time to get the value in UTC.
Can someone please help me with the algorithm (or point to an existing library) to parse the VTIMEZONE block and get the UTC offset at given time.
EDIT: I am working on python. So a python library would be great. It's OK if you suggest in some other language too, all I need is the algorithm. I can convert it to working code myself.
Upvotes: 0
Views: 559