How to Specify Timezone in ics File which will work efficiently with google,outlook and apple?

koustubh picture koustubh · Feb 26, 2016 · Viewed 23.9k times · Source

I want to generate an ics file which will be compatible with google, outlook and apple calendars. I am able to do it fine, but the problem is that I can't specify timezone block in file which will be compatible for above mentioned apps. I currently used X-Wr-timezone property which doesn't work with outlook and gives different time in google. I need the solution for this problem. My ics file:

BEGIN:VCALENDAR
PRODID:-//sample//sam Calendar//EN
VERSION:2.0
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
X-WR-TIMEZONE:America/Los_Angeles
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART;TZID=America/Los_Angeles:20160206T074400
DTEND;TZID=America/Los_Angeles:20160206T084400
DESCRIPTION:Your appointment Details:\n\nPatient Details:Kou Kul\nKeven\n\nAppointment Type:Counselling (30 min)\n\nThanks.
LOCATION: Pune
SEQUENCE:0
PRIORITY:5
STATUS:CONFIRMED
SUMMARY:Appointment Details:- John Bond
UID:X:201600U2800000A9Yp0EAF@sample
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR

Answer

luc picture luc · Feb 26, 2016

use the VTIMEZONE component before the VEVENT: https://tools.ietf.org/html/rfc5545#section-3.6.5

   BEGIN:VTIMEZONE
   TZID:America/New_York
   LAST-MODIFIED:20050809T050000Z
   BEGIN:STANDARD
   DTSTART:20071104T020000
   TZOFFSETFROM:-0400
   TZOFFSETTO:-0500
   TZNAME:EST
   END:STANDARD
   BEGIN:DAYLIGHT
   DTSTART:20070311T020000
   TZOFFSETFROM:-0500
   TZOFFSETTO:-0400
   TZNAME:EDT
   END:DAYLIGHT
   END:VTIMEZONE

So the final assembled ICS file would look like this (based on the OP's ICS file; N.B. on his 1st line the "R" of VCALENDAR was pushed to the beginning of "PRODID" on the second line, I have corrected it in the answer):

BEGIN:VCALENDAR
PRODID:-//sample//sam Calendar//EN
VERSION:2.0
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
X-WR-TIMEZONE:America/Los_Angeles
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID:America/New_York
LAST-MODIFIED:20050809T050000Z
BEGIN:STANDARD
DTSTART:20071104T020000
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20070311T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
DTSTART:20160206T074400
DTEND:20160206T084400
DESCRIPTION:Your appointment Details:\n\nPatient Details:Kou Kul\nKeven\n\nAppointment Type:Counselling (30 min)\n\nThanks.
LOCATION: Pune
SEQUENCE:0
PRIORITY:5
STATUS:CONFIRMED
SUMMARY:Appointment Details:- John Bond
UID:X:201600U2800000A9Yp0EAF@sample
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR

I have not tested this specific ICS, so cannot predict the behaviour of using both VTIMEZONE with X-WR-TIMEZONE.

Another point of subtlety is that the Date/Time format cannot include a timezone. So for example if you were to build this in PHP, you'd want to make sure that:

const DT_FORMAT = 'Ymd\THis';

e.g. DTSTART:20160206T074400

and NOT:

const DT_FORMAT = 'Ymd\THis\Z';

e.g. DTSTART:20160206T074400Z

This Date/Time format is important for the Date/Times in the VEVENT block. I have had success when there was a "Z" at the end of the "LAST_MODIFIED" field.

On a sidenote, the OP was working in the Los Angeles timezone, but this answer shows New York information in the VTIMEZONE block. The appropriate information for Los Angeles would have to be calculated (e.g. daylight savings offset, etc...)

Final observation, new line "\n" doesn't work with google calendar as of April 2018. iCal obeys it as long as "VERSION:2.0" is used.