From e2f749c86b07d38a52bf656ccbfdf13900be79d2 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 4 Jun 2008 13:22:11 +0000 Subject: [PATCH] "taking into account timezone of iso8601 date in bocal::date2ts(), eg. used in time-range filters in CalDAV" --- calendar/inc/class.bocal.inc.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/calendar/inc/class.bocal.inc.php b/calendar/inc/class.bocal.inc.php index 9f61527cf3..19713ebb63 100644 --- a/calendar/inc/class.bocal.inc.php +++ b/calendar/inc/class.bocal.inc.php @@ -1052,19 +1052,28 @@ class bocal { $date_in = $date; - switch(gettype($date)) { - case 'string': // YYYYMMDD or iso8601 YYYY-MM-DDThh:mm:ss string + case 'string': // YYYYMMDD or iso8601 YYYY-MM-DDThh:mm:ss[Z|[+-]hh:mm] string if (is_numeric($date) && $date > 21000000) { $date = (int) $date; // this is already as timestamp break; } - // ToDo: evaluate evtl. added timezone - + // evaluate evtl. added timezone + if (strlen($date) > 12) + { + if (substr($date,-1) == 'Z') + { + $time_offset = date('Z'); + } + elseif(preg_match('/([+-]{1})([0-9]{2}):?([0-9]{2})$/',$date,$matches)) + { + $time_offset = date('Z')-($matches[1] == '+' ? 1 : -1)*(3600*$matches[2]+60*$matches[3]); + } + } // removing all non-nummerical chars, gives YYYYMMDDhhmmss, independent of the iso8601 format - $date = str_replace(array('-',':','T','Z',' '),'',$date); + $date = str_replace(array('-',':','T','Z',' ','+'),'',$date); $date = array( 'year' => (int) substr($date,0,4), 'month' => (int) substr($date,4,2), @@ -1095,6 +1104,11 @@ class bocal $date = $this->now_su; break; } + if ($time_offset) + { + $date += $time_offset; + if (!$user2server) $date += $this->tz_offset_s; // we have to return user time! + } if ($user2server) { $date -= $this->tz_offset_s;