/usr/share/php/Horde/Timezone/Zone.php is in php-horde-timezone 1.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | <?php
/**
* Copyright 2011-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Jan Schneider <jan@horde.org>
* @package Timezone
*/
/**
* Class representing a set of "Rule" timezone database entries of the
* same name.
*
* @author Jan Schneider <jan@horde.org>
* @package Timezone
*/
class Horde_Timezone_Zone
{
/**
* The timezone ID.
*
* @var string
*/
protected $_name;
/**
* A Horde_Timezone object.
*
* @va Horde_Timezone
*/
protected $_tz;
/**
* Zone lines of this zone object.
*
* @var array
*/
protected $_info = array();
/**
* Constructor.
*
* @param string $name A timezone ID.
* @param Horde_Timezone $tz A Horde_Timezone object. Used to retrieve
* rules for this timezone.
*/
public function __construct($name, Horde_Timezone $tz)
{
$this->setTzid($name);
$this->_tz = $tz;
}
/**
* Sets the timezone ID.
*
* There are aliases for timezone IDs, it might be necessary to
* use one of those.
*
* @param string $name A timezone ID.
*/
public function setTzid($name)
{
$this->_name = $name;
}
/**
* Adds a Zone line to this zone object.
*
* @param array $info A parsed Zone line or continuation line.
*/
public function add($info)
{
$this->_info[] = $info;
}
/**
* Exports this zone to a VTIMEZONE component.
*
* @param Horde_Date $from The earliest date that we need timezone
* definitions for.
* @param Horde_Date $to The latest date.
*
* @return Horde_Icalendar_Vtimezone A VTIMEZONE component representing
* this timezone.
* @throws Horde_Timezone_Exception
*/
public function toVtimezone($from = null, $to = null)
{
if (!count($this->_info)) {
throw new Horde_Timezone_Exception('No rules found for timezone ' . $this->_name);
}
$tz = new Horde_Icalendar_Vtimezone();
$tz->setAttribute('TZID', $this->_name);
if (count($this->_info[0]) <= 3) {
// Zone has no start or end date, but DAYLIGHT and STANDARD
// components are required to have a DTSTART attribute [RFC
// 5545 3.8.2.4].
return $tz;
}
$startDate = $this->_getDate(0);
$startOffset = $this->_getOffset(0);
for ($i = 1, $c = count($this->_info); $i < $c; $i++) {
if ($to && $startDate->after($to)) {
continue;
}
$name = $this->_info[$i][2];
$endDate = count($this->_info[$i]) > 3 ? $this->_getDate($i) : null;
if ($from && $endDate && $endDate->before($from)) {
continue;
}
if ($this->_info[$i][1] == '-') {
// Standard time.
$component = new Horde_Icalendar_Standard();
} elseif (preg_match('/\d+(:(\d+))?/', $this->_info[$i][1])) {
// Indiviual rule not matching any ruleset.
$component = new Horde_Icalendar_Daylight();
} else {
// Represented by a ruleset.
$startOffset = $this->_getOffset($i);
$this->_tz->getRule($this->_info[$i][1])
->addRules(
$tz,
$this->_name,
$name,
$startOffset,
$from && $from->after($startDate) ? $from : $startDate,
$to && $to->before($endDate) ? $to : $endDate
);
$startDate = $endDate;
// Continue, because addRules() already adds the
// component to $tz.
continue;
}
$component->setAttribute('DTSTART', $startDate);
$component->setAttribute('TZOFFSETFROM', $startOffset);
$startOffset = $this->_getOffset($i);
$component->setAttribute('TZOFFSETTO', $startOffset);
$component->setAttribute('TZNAME', $name);
$tz->addComponent($component);
}
return $tz;
}
/**
* Calculates a date from the date columns of a Zone line.
*
* @param integer $line A line number.
*
* @return Horde_Date The date of this line.
*/
protected function _getDate($line)
{
$date = array_slice($this->_info[$line], 3);
$year = $date[0];
$month = isset($date[1]) ? Horde_Timezone::getMonth($date[1]) : 1;
$day = isset($date[2]) ? $date[2] : 1;
$time = isset($date[3]) && $date[3] != '-' ? $date[3] : 0;
preg_match('/(\d+)(?::(\d+))?(?::(\d+))?(w|s|u)?/', $time, $match);
if (!isset($match[2])) {
$match[2] = 0;
}
if (!isset($match[3])) {
$match[3] = 0;
}
switch (substr($time, -1)) {
case 's':
// Standard time. Not sure what to do about this.
break;
case 'u':
// UTC, add offset.
$offset = $this->_getOffset($line);
$factor = $offset['ahead'] ? 1 : -1;
$match[1] += $factor * $offset['hour'];
$match[2] += $factor * $offset['minute'];
case 'w':
default:
// Wall time, nothing to do.
break;
}
return new Horde_Date(array('year' => $year,
'month' => $month,
'mday' => $day,
'hour' => $match[1],
'min' => $match[2],
'sec' => $match[3]));
}
/**
* Calculates an offset from the offset column of a Zone line.
*
* @param integer $line A line number.
*
* @return array A hash describing the offset.
*/
protected function _getOffset($line)
{
$offset = $this->_info[$line][0];
preg_match('/(-)?(\d+):(\d+)/', $offset, $match);
return array('ahead' => $match[1] != '-',
'hour' => $match[2],
'minute' => $match[3]);
}
}
|