first steps for better timezone management

This commit is contained in:
2012-12-28 20:10:45 +00:00
parent c0e51e294b
commit 7d42712f43
5 changed files with 152 additions and 11 deletions

View File

@@ -7,8 +7,8 @@ X-WR-CALNAME:Testkalender
X-WR-TIMEZONE:Europe/Berlin
X-WR-CALDESC:Nur zum testen vom Google Kalender
BEGIN:VEVENT
DTSTART:20121112T173000Z
DTEND:20121116T180000Z
DTSTART;TZID="W. Europe":20121227T100000
DTEND;TZID="W. Europe":20121227T110000Z
DTSTAMP:20110121T195741Z
UID:1koigufm110c5hnq6ln57murd4@google.com
CREATED:20110119T142901Z

View File

@@ -176,7 +176,7 @@ class ICal {
* @return {array} array("VCALENDAR", "Begin")
*/
public function keyValueFromString($text) {
preg_match("/(^[^a-z:]+[;a-zA-Z=\/]*)[:]([\w\W]*)/", $text, $matches);
preg_match("/(^[^a-z:]+[;a-zA-Z=\/\"\']*)[:]([\w\W]*)/", $text, $matches);
error_log("macthes: " . count($matches). " " . $text);
if (count($matches) == 0) {
@@ -195,7 +195,11 @@ class ICal {
*
* @return {int}
*/
public function iCalDateToUnixTimestamp($icalDate) {
public function iCalDateToUnixTimestamp($icalDate) {
/* timestring format */
$utc = strpos("zZ",substr($icalDate, -1)) === false ? false : true;
$icalDate = str_replace('T', '', $icalDate);
$icalDate = str_replace('Z', '', $icalDate);
@@ -206,6 +210,9 @@ class ICal {
$pattern .= '([0-9]{0,2})'; // 5: MM
$pattern .= '([0-9]{0,2})/'; // 6: SS
preg_match($pattern, $icalDate, $date);
// Unix timestamp can't represent dates before 1970
if ($date[1] <= 1970) {
@@ -221,11 +228,14 @@ class ICal {
(int)$date[1]);
$utcdate = new DateTime();
$utcdate->setTimestamp($timestamp);
$utcdate->setTimezone(new DateTimeZone($this->default_timezone));
$utcoffset = $utcdate->getOffset();
if($utc) {
$utcdate = new DateTime();
$utcdate->setTimestamp($timestamp);
$utcdate->setTimezone(new DateTimeZone($this->default_timezone));
$utcoffset = $utcdate->getOffset();
} else {
$utcoffset = 0;
}
return ($timestamp + $utcoffset);
}