Commit 1ea1998c authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #537 in ZP/z-push from...

Merge pull request #537 in ZP/z-push from bugfix/ZP-1224-caldav-pass-php-supported-timezone to develop

* commit '010e6e22':
  ZP-1224 Use TimezoneUtil functions to generate timezone string.
  ZP-1224 Pass PHP supported timezone to DateTimeZone.
parents 16c9740c 010e6e22
......@@ -538,7 +538,7 @@ class BackendCalDAV extends BackendDiff {
$timezones = $ical->GetComponents("VTIMEZONE");
$timezone = "";
if (count($timezones) > 0) {
$timezone = TimezoneUtil::ParseTimezone($timezones[0]->GetPValue("TZID"));
$timezone = TimezoneUtil::GetPhpSupportedTimezone($timezones[0]->GetPValue("TZID"));
}
if (!$timezone) {
$timezone = date_default_timezone_get();
......@@ -1449,65 +1449,9 @@ class BackendCalDAV extends BackendDiff {
* @throws Exception
*/
private function _GetTimezoneString($timezone, $with_names = true) {
// 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));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCalDAV->_GetTimezoneString(): using '%s' timezone", $timezone));
$tz = TimezoneUtil::GetFullTZFromTZName($timezone);
$blob = TimezoneUtil::GetSyncBlobFromTZ($tz);
return base64_encode($blob);
}
}
\ No newline at end of file
......@@ -1359,4 +1359,23 @@ class TimezoneUtil {
}
return self::getMSTZnameFromTZName(trim($timezone, '"'));
}
/**
* Returns a timezone supported by PHP for DateTimeZone constructor.
* @see http://php.net/manual/en/timezones.php
*
* @param string $timezone
*
* @access public
* @return string
*/
public static function GetPhpSupportedTimezone($timezone) {
if (in_array($timezone, DateTimeZone::listIdentifiers())) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("TimezoneUtil::GetPhpSupportedTimezone(): '%s' is a PHP supported timezone", $timezone));
return $timezone;
}
$dtz = date_default_timezone_get();
ZLog::Write(LOGLEVEL_DEBUG, sprintf("TimezoneUtil::GetPhpSupportedTimezone(): '%s' is not a PHP supported timezone. Returning default timezone: '%s'", $timezone, $dtz));
return $dtz;
}
}
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