I am creating google vcalender ICS file and send it on email using PHP.
But i am facing problem is Time not showing correctly on google calender. In my example i have passed time as 01:00:00 AM(IST) but when i import my ics file calender showing 12am(IST).
When i change my google calender setting timezone to United State (EST) it showing time as 1:30pm (EST) but it should be 2:30 pm(EST).
What is wrong with my code ?
Here is my PHP code to generate ics file and send as email:
$user_timezone = dynamic timezone; // my timezone = Asia/Kolkata
$demo_date = 2014-12-05;
$demo_time = 01:00:00 AM;
$meeting_date = $demo_date .' '.$demo_time;
date_default_timezone_set($user_timezone);
$date = date('Y-m-d H:i:s A', strtotime($meeting_date));
// Event time stamp
$timestamp = strtotime(date($meeting_date));
// Event start date and end date
$start_date = date('Ymd', strtotime($meeting_date)) ."T". date('H:i:s A', $timestamp);
$end_date = date('Ymd', strtotime($meeting_date)) ."T". date('H:i:s A', $timestamp);
//calender unique ID
$cal_uid = date('Ymd').'T'.date('His')."-".rand();
//Message send to Calender
$ical = "BEGIN:VCALENDAR\n";
$ical .= "VERSION:2.0\n";
$ical .= "PRODID:-//Forest//Forest Inquiry v1.0//EN\n";
$ical .= "CALSCALE:GREGORIAN\n";
$ical .= "METHOD:PUBLISH\n";
$ical .= "X-WR-CALNAME:Forest Inquiry\n";
$ical .= "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n";
$ical .= "BEGIN:VTIMEZONE\n";
$ical .= "X-WR-TIMEZONE:{$user_timezone}\n";
$ical .= "TZID:{$user_timezone}\n";
$ical .= "TZURL:http://tzurl.org/zoneinfo-outlook/{$user_timezone}\n";
$ical .= "X-LIC-LOCATION:{$user_timezone}\n";
$ical .= "END:VTIMEZONE\n";
$ical .= "BEGIN:VEVENT\n";
$ical .= "DTSTAMP:".date('Ymd\THis\Z')."\n";
$ical .= "DTSTART;TZID={$user_timezone}:{$start_date}\n";
$ical .= "DTEND;TZID={$user_timezone}:{$end_date}\n";
$ical .= "STATUS:CONFIRMED\n";
$ical .= "SUMMARY:{$subject}\n";
$ical .= "DESCRIPTION:{$meeting_description}\n";
$ical .= "ORGANIZER;CN=Forest:MAILTO:[email protected]\n";
$ical .= "CLASS:PUBLIC\n";
$ical .= "CREATED:{$start_date}Z\n";
$ical .= "LOCATION:{$meeting_location}\n";
$ical .= "URL:\n";
$ical .= "SEQUENCE:1\n";
$ical .= "LAST-MODIFIED:".date('Ymd\THis\Z')."\n";
$ical .= "UID:{$subject}[email protected]\n";
$ical .= "END:VEVENT\n";
$ical .= "END:VCALENDAR";
$file_name = 'XYZ'.$first_name;
// Mail parameters
$newline = "\r\n";
$headers = "From:test\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/calendar; charset=utf-8; name=$file_name.ics; method=REQUEST".$newline;
$headers .= "Content-Disposition: inline; filename=$file_name.ics".$newline;
$headers .= "Content-Transfer-Encoding: 7bit";
mail('[email protected]', $subject, $ical, $headers);
Here is my ICS file:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Forest//Forest Inquiry v1.0//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Forest Inquiry
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VTIMEZONE
TZID:Asia/Kolkata
TZURL:http://tzurl.org/zoneinfo-outlook/Asia/Kolkata
X-LIC-LOCATION:Asia/Kolkata
END:VTIMEZONE
BEGIN:VEVENT
DTSTAMP:20141205T104434Z
DTSTART;TZID=Asia/Kolkata:20141211T053000
DTEND;TZID=Asia/Kolkata:20141211T053000
STATUS:CONFIRMED
SUMMARY:Forest Inquiry by testing Testing
DESCRIPTION:First Name :testing\n
ORGANIZER;CN=Forest:MAILTO:[email protected]
CLASS:PUBLIC
CREATED:20141211T053000Z
LOCATION:At Forest
URL:
SEQUENCE:1
LAST-MODIFIED:20141205T104434Z
UID:Forest Inquiry by testing [email protected]
END:VEVENT
END:VCALENDAR
Looking at the Timezone URL you can see the correction for the daylightsaving and standard time. Add the STANDARD and DAYLIGHT for IST to you vcal and it should work.