2017-04-14 80 views
0

我使用iCalcreator(v2.6)PHP庫創建.vcs文件。當事件在Outlook中打開時(最新版本,我不知道其他版本),會議日期/時間不會調整到當地時間。我認爲它可能與this有關,但設置X-MICROSOFT-CDO-TZID值似乎沒有幫助。我希望有人知道一些關於vcs文件創建的人可以指出我正確的方向。下面是我創建的VCS文件:無法在不同時區打開時調整vCalendar(vcs)

BEGIN:VCALENDAR 
CALSCALE:GREGORIAN 
METHOD:PUBLISH 
PRODID:-//127.0.53.53//NONSGML iCalcreator 2.6// 
VERSION:2.0 
BEGIN:VTIMEZONE 
TZID:US/Pacific 
LAST-MODIFIED:20040110T032845Z 
X-MICROSOFT-CDO-TZID:13 
BEGIN:DAYLIGHT 
DTSTART:19900404T010000 
TZOFFSETFROM:-0800 
TZOFFSETTO:-0700 
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1SU 
TZNAME:PDT 
END:DAYLIGHT 
BEGIN:STANDARD 
DTSTART:19901026T060000 
TZOFFSETFROM:-0700 
TZOFFSETTO:-0800 
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU 
TZNAME:PST 
END:STANDARD 
END:VTIMEZONE 
BEGIN:VEVENT 
UID:[email protected] 
DTSTAMP:20170413T185736Z 
DESCRIPTION:sdfg\n\nSome awesome description 
DTSTART:20170419T180000 
DURATION:PT3H0M0S 
LOCATION:The best place in the world 
SUMMARY:One fine summary 
END:VEVENT 
END:VCALENDAR 

回答

0

晚年,但在這裏它是如何工作的我,也許這將幫助別人誰在這個問題發生。

我從來沒有嘗試TZOFFSETFROM ...所以不知道這是關於什麼,或者即使它應該工作。但是,如果將時區放入DTSTART和DTEND中,它將自動調整。您只需要日期爲UTC,就像您最後修改的日期一樣。我不喜歡這樣($start$end是PHP的DateTime對象):

"DTSTART:".$start->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z').$eol. 
"DTEND:".$end->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z') 

所以,基本上,所有做的就是把日期爲UTC時區,然後一個Z在結束格式化的日期/時間與客戶溝通。

一個完整的工作示例(事件是有幫助的任何人)是:

<?php 
    date_default_timezone_set('America/New_York'); 
    //CONFIGURE HERE 
    $fromName   = "John Doe"; 
    $fromEmail   = "[email protected]"; 
    $toName    = "Your Name"; 
    $toEmail   = '[email protected]'; 
    $start    = new DateTime('2017-08-15 15:00'); 
    $end    = new DateTime('2017-08-15 16:00'); 
    $summary   = "Hello World Event"; 
    //END CONFIGURATION 

    $uid    = ""; 
    $headers   = array(); 
    $boundary   = "_CAL_" . uniqid("B",true) . "_B_"; 
    $headers[]   = "MIME-Version: 1.0"; 
    $headers[]   = "Content-Type: multipart/alternative; boundary=\"".$boundary."\""; 
    $headers[]   = "To: \"{$toName}\" <{$toEmail}>"; 
    $headers[]   = "From: \"{$fromName}\" <{$fromEmail}>"; 

    $calendarLines  = array(
     "BEGIN:VCALENDAR", 
     "METHOD:REQUEST", 
     "PRODID:-//PHP//MeetingRequest//EN", 
     "VERSION:2.0", 
     "BEGIN:VEVENT", 
     "ORGANIZER;CN={$fromName}:MAILTO:{$fromEmail}", 
     "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN={$toName}:MAILTO:{$toEmail}", 
     "DESCRIPTION:{$summary}", 
     "SUMMARY:{$summary}", 
     "DTSTART:".$start->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z'), 
     "DTEND:".$end->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z'), 
     "UID:{$uid}", 
     "CLASS:PUBLIC", 
     "PRIORITY:5", 
     "DTSTAMP:".gmdate('Ymd\THis\Z'), 
     "TRANSP:OPAQUE", 
     "STATUS:CONFIRMED", 
     "SEQUENCE:0", 
     "LOCATION:123 Any Street", 
     "BEGIN:VALARM", 
     "ACTION:DISPLAY", 
     "DESCRIPTION:REMINDER", 
     "TRIGGER;RELATED=START:-PT15M", 
     "END:VALARM", 
     "END:VEVENT", 
     "END:VCALENDAR" 
    ); 


    $calendarBase64  = base64_encode(implode("\r\n",$calendarLines)); 
    //ensure we don't have lines longer than 70 characters for older computers: 
    $calendarResult  = wordwrap($calendarBase64,68,"\n",true); 

    $emailLines = array(
     "--{$boundary}", 
     "Content-Type: text/html; charset=\"iso - 8859 - 1\"", 
     "Content-Transfer-Encoding: quoted-printable", 
     "", 
     "<html><body>", 
     "<h1>Hello World</h1>", 
     "<p>This is a calendar event test</p>", 
     "</body></html>", 
     "", 
     "--{$boundary}", 
     "Content-Type: text/calendar; charset=\"utf - 8\"; method=REQUEST", 
     "Content-Transfer-Encoding: base64", 
     "", 
     $calendarResult, 
     "", 
     "--{$boundary}--" 
    ); 
    $emailContent = implode("\n",$emailLines); 

    $headersResult  = implode("\n",$headers); 
    mail($toEmail, $summary, $emailContent, $headersResult); 
    echo("<pre>".htmlentities($headersResult)."\n\n".htmlentities($emailContent)."</pre>"); 
    echo("<br /><br />"); 
    echo("<pre>".base64_decode($calendarResult)."</pre>");