2014-12-05 71 views
1

我正在創建谷歌vcalender ICS文件,並使用PHP發送電子郵件。谷歌vcalender顯示錯誤的時間

但我面臨的問題是時間沒有正確顯示在谷歌日曆。 在我的例子中,我已經將時間作爲01:00:00 AM(IST)傳遞,但是當我導入顯示12am(IST)的ics文件日曆時。

當我將我的谷歌日曆設置時區更改爲美國(美國東部時間)時,顯示時間爲下午1:30(東部標準時間),但應該是下午2:30(東部標準時間)。

我的代碼有什麼問題?

這是我的PHP代碼生成ics文件和發送電子郵件:

$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].com\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); 

這裏是我的ICS文件:

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 

回答

0

綜觀時區的網址,你可以看到的修正日光節約和標準時間。將IST的STANDARD和DAYLIGHT添加到你的vcal中,它應該可以工作。

BEGIN:VCALENDAR 
PRODID:-//tzurl.org//NONSGML Olson 2014g//EN 
VERSION:2.0 
BEGIN:VTIMEZONE 
TZID:Asia/Kolkata 
TZURL:http://tzurl.org/zoneinfo/Asia/Kolkata 
X-LIC-LOCATION:Asia/Kolkata 
BEGIN:STANDARD 
TZOFFSETFROM:+055328 
TZOFFSETTO:+055320 
TZNAME:HMT 
DTSTART:18800101T000000 
RDATE:18800101T000000 
END:STANDARD 
BEGIN:STANDARD 
TZOFFSETFROM:+055320 
TZOFFSETTO:+0630 
TZNAME:BURT 
DTSTART:19411001T000000 
RDATE:19411001T000000 
END:STANDARD 
BEGIN:STANDARD 
TZOFFSETFROM:+0630 
TZOFFSETTO:+0530 
TZNAME:IST 
DTSTART:19420515T000000 
RDATE:19420515T000000 
RDATE:19451015T000000 
END:STANDARD 
BEGIN:DAYLIGHT 
TZOFFSETFROM:+0530 
TZOFFSETTO:+0630 
TZNAME:IST 
DTSTART:19420901T000000 
RDATE:19420901T000000 
END:DAYLIGHT 
END:VTIMEZONE 
END:VCALENDAR