使用 Ical 时如何停止夏令时更改?

how to stop daylight saving changes when using Ical?

基本上,当用户点击我的下载按钮时,我会使用 href="download.php",从那天起,我会向用户日历添加 84 天的日历通知。

我遇到的问题是夏令时开始后突然变为 09:00。

我想停止它并确保所有日历通知都收到 08:00。

但我似乎不知道该怎么做。

这是我的 download.php 代码:

<?php
header("Content-type: text/calendar");//iphone
header("Content-Disposition: attachment; filename=pillintake.ics");//iphone
// the iCal date format. Note the Z on the end indicates a UTC timestamp.
define('DATE_ICAL', 'Ymd\THis\Z');

// max line length is 75 chars. New line is \n


$output = "BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//dev//test Schedule//EN\n";

$startTime = strtotime( date('Y-m-d 08:00') );
$endTime = strtotime($Date. ' + 84 days');



$startTime = str_replace("Z","",$startTime);

// Loop between timestamps, 24 hours at a time
$count = 1;
for ( $i = $startTime; $i <= $endTime; $i = $i + 86400 ) {

$currentDate =  date(DATE_ICAL, $i);
$output .=
"BEGIN:VTIMEZONE
TZID:Europe/Stockholm
X-LIC-LOCATION:Europe/Stockholm 
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100 
TZOFFSETTO:+0200 
TZNAME:CEST 
DTSTART:19700329T020000 
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200 
TZOFFSETTO:+0100 
TZNAME:CET 
DTSTART:19701025T030000 
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
SUMMARY:Ta din tablett
DESCRIPTION: Glöm inte! \n\n
UID:0000".$count."
STATUS:OK
DTSTART:" . $currentDate . "
DTEND:" .$currentDate . "
LAST-MODIFIED:" .$currentDate . "
LOCATION:
END:VEVENT\n";
$count = $count +1;
}


$output .= "END:VCALENDAR";

echo $output;

?>

虽然你的问题是如何停止夏令时的变化我假设你只是希望你的通知总是在同一当地时间发生而不考虑 DST .

您的日历文件就快完成了。关键点就像你定义了一个VTIMEZONE组件,但是你还需要告诉日历工具哪个事件属性(DTSTARTDTEND,...)应该使用这个 TZID 属性

在你的情况下,你的提醒应该有两行这样的

...
DTSTART;TZID=Europe/Stockholm:20160323T00000 DTEND;TZID=Europe/Stockholm:20160323T00000
...

更多详情可以参考RFC5545- Time Zone Identifier and RFC5545 - event component

您的代码看起来不错,但您可能需要检查一些内容。 如果您的 DTSTART 值包含 'Z',那么您需要将其删除。

请尝试以下代码:

...
$currentDate =  date(DATE_ICAL, $i);
$currentDate = str_replace("Z","",$currentDate);
$output .=
"BEGIN:VTIMEZONE
TZID:Europe/Stockholm
X-LIC-LOCATION:Europe/Stockholm 
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100 
TZOFFSETTO:+0200 
TZNAME:CEST 
DTSTART:19700329T020000 
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200 
TZOFFSETTO:+0100 
TZNAME:CET 
DTSTART:19701025T030000 
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
SUMMARY:Ta din tablett
DESCRIPTION: Glöm inte! \n\n
UID:0000".$count."
STATUS:OK
DTSTART;TZID=Europe/Stockholm:" . $currentDate . " 
DTEND;TZID=Europe/Stockholm:" .$currentDate . "
LAST-MODIFIED:" .$currentDate . "
LOCATION:
END:VEVENT\n";
$count = $count +1;
}

...

希望对您有所帮助