Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing ICS into Google Calendar with correct timezone

I'm trying to import a simple ics file into Google calendar. However, even though I have the timezone specified, Google calendar still imports the wrong event time. (Although it does say that the wrong time is in the correct timezone.)

Here is a sample of my ics file:

BEGIN:VCALENDAR
BEGIN:VEVENT
DESCRIPTION: Test_Description
DTEND;TZID=US-Pacific:20140606T180000
DTSTART;TZID=US-Pacific:20140606T170000
LOCATION:Test_Location
SUMMARY:Test_Summary
UID:20140606T150000@NL
END:VEVENT
END:VCALENDAR

This event should show up as occurring on June 6, from 5PM-6PM Pacific Standard Time. However, on my calendar it shows up as occurring on June 6, from 10AM-11AM PST.

I think (although have not implemented) a hack to just change everything to UTC and adjust the event time accordingly might work. However, this would be a little annoying to implement and honestly Google Calendar should be able to handle this simple of an import.

Does anyone have any suggestions to deal with this, or see any bugs in my ICS file?

Thanks!

like image 250
sesquiped Avatar asked May 30 '14 21:05

sesquiped


People also ask

How do I stop Google Calendar from changing time zones?

Open Google Calendar, tap the Menu button in the upper-left corner and select Settings. On the next screen, tap General and turn off the button next to “Use device time zone” to stop appointments from shifting.

Can you import ICS file into Google Calendar?

Import your . Select the . ics file you downloaded and choose which calendar to add it to. Then press the “Import” button to save it to your Google Calendar.


2 Answers

Normally it is required to include VTIMEZONE objects. Many people are starting to omit that, but if you do, at least use an olson-identifier. This should be enough for google calendar to pick up the correct timezone.

An example of an olson identifier is Europe/Amsterdam. Look up the identifier the most appropriate for you. Presumably this is something like America/Los_Angeles.

like image 160
Evert Avatar answered Sep 19 '22 13:09

Evert


To make your ICS work with Google's "Add by URL..." specify your timestamps in UTC and add the X-WR-TIMEZONE. Timestamp must have the Z at the end to mark the timestamp as UTC:

DTSTART:20140102T110000Z

Also add the timezone specification in the VCALENDAR block like this:

X-WR-TIMEZONE:Europe/Zurich

After adding the calendar in Google Calendar, the time zone for should be set correctly in the calendar's settings.

If you are using PHP to generate the ICS, you can convert the timestamps to UTC like this:

// The timestamp in your local time and your local time zone
$timestamp = "01.01.2016 12:00";
$timezone = new DateTimeZone('Europe/Zurich');

// The UTC timezone
$utc = new DateTimeZone('UTC');

// Create a DateTime object from your timestamp using your local timezone
$datetime = DateTime::createFromFormat("d.m.Y H:i",$timestamp, $timezone);

// Set the timezone on the object to UTC.
$datetime->setTimezone($utc);

// Print the time in UTC and use the correct format for ICS
echo $datetime->format('Ymd\THis\Z');

This also works on Apple's iPhones.

like image 21
chris Avatar answered Sep 22 '22 13:09

chris