Commit 010e6e22 authored by Manfred Kutas's avatar Manfred Kutas

ZP-1224 Use TimezoneUtil functions to generate timezone string.

Released under the Affero GNU General Public License (AGPL) version 3.
parent ccc0e440
......@@ -1450,65 +1450,8 @@ class BackendCalDAV extends BackendDiff {
*/
private function _GetTimezoneString($timezone, $with_names = true) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCalDAV->_GetTimezoneString(): using '%s' timezone", $timezone));
// UTC needs special handling
if ($timezone == "UTC")
return base64_encode(pack('la64vvvvvvvvla64vvvvvvvvl', 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0));
try {
//Generate a timezone string (PHP 5.3 needed for this)
$timezone = new DateTimeZone($timezone);
$trans = $timezone->getTransitions(time());
$stdTime = null;
$dstTime = null;
if (count($trans) < 3) {
throw new Exception();
}
if ($trans[1]['isdst'] == 1) {
$dstTime = $trans[1];
$stdTime = $trans[2];
}
else {
$dstTime = $trans[2];
$stdTime = $trans[1];
}
$stdTimeO = new DateTime($stdTime['time']);
$stdFirst = new DateTime(sprintf("first sun of %s %s", $stdTimeO->format('F'), $stdTimeO->format('Y')), timezone_open("UTC"));
$stdBias = $stdTime['offset'] / -60;
$stdName = $stdTime['abbr'];
$stdYear = 0;
$stdMonth = $stdTimeO->format('n');
$stdWeek = floor(($stdTimeO->format("j")-$stdFirst->format("j"))/7)+1;
$stdDay = $stdTimeO->format('w');
$stdHour = $stdTimeO->format('H');
$stdMinute = $stdTimeO->format('i');
$stdTimeO->add(new DateInterval('P7D'));
if ($stdTimeO->format('n') != $stdMonth) {
$stdWeek = 5;
}
$dstTimeO = new DateTime($dstTime['time']);
$dstFirst = new DateTime(sprintf("first sun of %s %s", $dstTimeO->format('F'), $dstTimeO->format('Y')), timezone_open("UTC"));
$dstName = $dstTime['abbr'];
$dstYear = 0;
$dstMonth = $dstTimeO->format('n');
$dstWeek = floor(($dstTimeO->format("j")-$dstFirst->format("j"))/7)+1;
$dstDay = $dstTimeO->format('w');
$dstHour = $dstTimeO->format('H');
$dstMinute = $dstTimeO->format('i');
$dstTimeO->add(new DateInterval('P7D'));
if ($dstTimeO->format('n') != $dstMonth) {
$dstWeek = 5;
}
$dstBias = ($dstTime['offset'] - $stdTime['offset']) / -60;
if ($with_names) {
return base64_encode(pack('la64vvvvvvvvla64vvvvvvvvl', $stdBias, $stdName, 0, $stdMonth, $stdDay, $stdWeek, $stdHour, $stdMinute, 0, 0, 0, $dstName, 0, $dstMonth, $dstDay, $dstWeek, $dstHour, $dstMinute, 0, 0, $dstBias));
}
else {
return base64_encode(pack('la64vvvvvvvvla64vvvvvvvvl', $stdBias, '', 0, $stdMonth, $stdDay, $stdWeek, $stdHour, $stdMinute, 0, 0, 0, '', 0, $dstMonth, $dstDay, $dstWeek, $dstHour, $dstMinute, 0, 0, $dstBias));
}
}
catch (Exception $e) {
// If invalid timezone is given, we return UTC
return base64_encode(pack('la64vvvvvvvvla64vvvvvvvvl', 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0));
}
return base64_encode(pack('la64vvvvvvvvla64vvvvvvvvl', 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0));
$tz = TimezoneUtil::GetFullTZFromTZName($timezone);
$blob = TimezoneUtil::GetSyncBlobFromTZ($tz);
return base64_encode($blob);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment