ICS文件动态时区问题


ICS file dynamic timezone issue

我试图在PHP中动态生成ics文件,其中时区根据给定的位置是动态的。一切都很好,但有一个夏令时问题,即它显示一个小时左右的时差。现在为了解决这个问题,我必须动态地使用DAYLIGHT。但是我不知道如何动态地使用它,或者从哪里可以得到与给定时区相关的TZOFFSETFROMTZOFFSETTO偏移量。

例如:

    $timeZone = "America/Denver" // dynamically fetched from DB
      $ical = "BEGIN:VCALENDAR'n";
      $ical .= "VERSION:2.0'n";
      $ical .= "PRODID:-//LokalMotion//LokalMotion Events v1.0//EN'n";
      $ical .= "CALSCALE:GREGORIAN'n";
      $ical .= "METHOD:PUBLISH'n";
      $ical .= "X-WR-CALNAME:LokalMotion Events'n";
      $ical .= "X-MS-OLK-FORCEINSPECTOROPEN:TRUE'n";
      $ical .= "BEGIN:VTIMEZONE'n";
      $ical .= "TZID:{$timeZone}'n";
      $ical .= "TZURL:http://tzurl.org/zoneinfo-outlook/{$timeZone}'n";
      $ical .= "X-LIC-LOCATION:{$timeZone}'n";
      $ical .= "END:VTIMEZONE'n";
      $ical .= "BEGIN:VEVENT'n";
      $ical .= "DTSTAMP:".date('Ymd'THis'Z')."'n";
      $ical .= "DTSTART;TZID={$timeZone}:{$start_date}'n";
      $ical .= "DTEND;TZID={$timeZone}:{$end_date}'n";
      $ical .= "STATUS:CONFIRMED'n";
      $ical .= "SUMMARY:{$title}'n";
      $ical .= "DESCRIPTION:{$description}'n";
      $ical .= "ORGANIZER;CN=Reminder:MAILTO:support@mysite.com'n";
      $ical .= "CLASS:PUBLIC'n";
      $ical .= "CREATED:{$start_date}Z'n";
      $ical .= "LOCATION:{$location}'n";
      $ical .= "URL:http://www.mysite.com'n";
      $ical .= "SEQUENCE:1'n";
      $ical .= "LAST-MODIFIED:".date('Ymd'THis'Z')."'n";
      $ical .= "UID:{$title}-support@mysite.com'n";
      $ical .= "END:VEVENT'n";
      $ical .= "END:VCALENDAR";    
echo $ical;

现在如何根据位置动态使用日光,比如位置可以是'America/Caracas' ..等

$ical .= "BEGIN:DAYLIGHT";
$ical .= "TZOFFSETFROM:{}"; //I need this dynamic
$ical .= "TZOFFSETTO:{}";//I need this dynamic
$ical .= "TZNAME:EDT";
$ical .= "DTSTART;TZID={$timeZone}:{$start_date}'n";
$ical .= "RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU";
$ical .= "END:DAYLIGHT";

在转换时间和日期之前,您应该在PHP中设置正确的时区,以便引擎知道您正在使用的时区的时间特征:

date_default_timezone_set('America/Mexico_City');
$start_date = date('c', time());   // ISO date 8601 of "right now"
$start_zone = date('O', time());   // TZOFFSETFROM format  of "right now"
date_default_timezone_set('America/Denver');
$to_zone = date('O', time());   // TZOFFSETTO of "right now"

希望能有所帮助