Question

I have an ISO DATETIME format parsed from web calendar ICS files. I have created calendar event in google and yahoo. In google, I have created for the time of 11:00 to 11:30 IST. In yahoo, I have created for the time of 11:30 to 11:45 IST.

I have received ICS files for both the events. My problem is with the event start time and end time in the ICS files.

Google Start time - 20140218T060000Z (provides GMT time)

Yahoo Start time - 20140218T113000Z (provides local time)

How can I check if the timezone in the ISO datetime is GMT and convert it to GMT if not? Please help me to achieve this. Thanks in advance.

Was it helpful?

Solution

There should be a timezone declaration in the ical file you can use.

The RFC places this on the DTSTART, for example:

DTSTART;TZID=America/New_York:19980119T020000

But ical is not a very exact "science", it seems like everybody uses it different. I've seen timezone declarations like this:

X-WR-TIMEZONE:Europe/Berlin

which only show up once in the ical file.

After creating a DateTime object you can use DateTime::setTimezone to set it. Example from the PHP documentation:

$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP') . "\n";

$date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo $date->format('Y-m-d H:i:sP') . "\n";

OTHER TIPS

As Gerald indicates the difference comes from the fact that the DTSTART (and by the way also the DTEND) properties of your event are referenced either explicitly (as per RFC 5545 - time zone identifier) or implicitely via X-WR-TIMEZONE (Apple iCal).

In the first case you have to handle the VTIMEZONE component (RFC5545 - VTIMEZONE component). For which you will need an ICalendar parser in PHP that supports timezones

In the second case you have to refer to the Olson database, and may need to use timezonedb instead of the default php one.

However you should probably read this blog entry from J. Dunnell on possible pitfalls of dealing with X-WR-TIMEZONE before getting started on this journey...

you can use the date and strtotime functions in php.

say

  // apply this to all your times
  $start_time = "20140218T060000Z";
  $timeZone = date("e",strtotime($start_time));

  if($timeZone != "UTC"){ // UTC is same as GMT in case you're wondering
      $start_time_gmt = gmdate("Ymd\THis\Z",$start_time); // the \T an \Z are key characters for the date function so you need to escape them if you want to display it in that format
  }

References: http://www.php.net/manual/en/function.date.php

http://php.net/strtotime

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top