vCalendar/iCalendar parsing timezone

eselk picture eselk · Jul 11, 2012 · Viewed 7.8k times · Source

I'm writing some code in C++ to parse vCal/iCal format and it correctly handles UTC and local formats, but now I've found a program that is creating this more complex format that uses specific timezones and I'm not able to figure out how to parse it correctly. Here is an example (sorry for the multi-line formatting, tried several things to fix):

BEGIN:VCALENDAR
METHOD:REQUEST
PRODID:Microsoft CDO for Microsoft Exchange
VERSION:2.0
BEGIN:VTIMEZONE
TZID:(GMT-06.00) Central Time (US & Canada)
X-MICROSOFT-CDO-TZID:11
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0600
RRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0600
TZOFFSETTO:-0500
RRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
DTSTAMP:20120709T210422Z
DTSTART;TZID="(GMT-06.00) Central Time (US & Canada)":20120711T110000
SUMMARY:DR Kickoff Call
LOCATION:GoToMeeting Invitation
DTEND;TZID="(GMT-06.00) Central Time (US & Canada)":20120711T120000
DESCRIPTION:Hi Guys
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR

I want to convert DTSTART to UTC. I know I need to use TZOFFSETTO, but how do I (in a robust manner) know if I should use the STANDARD or DAYLIGHT value? In the sample below, it is today's date, and STANDARD should be used (based on the actual meeting time I know it to be), but how would I programatically know that?

I don't think it would be robust to make any assumptions based on offsets or TZID names, because these vCal/iCal formats don't always map to anything standard. It's a shame the generating app can't just use UTC, but not like I have control over GoToMeeting.com, and they are very popular so I also can't just ignore this issue.

The only thing I can see that might tell me which value to use would be the RRULE, but do I really need to get in to repeating DTSTART based on all of the various possible RRULE values to figure out which one to apply?

My app needs to run on WinXP+ and I don't want to require Outlook or CDO to parse these for me.

Answer

Sterling Bourne picture Sterling Bourne · Sep 7, 2012

Actually, you can use the TZID names, as documented here: http://msdn.microsoft.com/en-us/library/aa563018(loband).aspx