3
* Class representing vTimezones.
5
* Copyright 2003-2013 Horde LLC (http://www.horde.org/)
7
* See the enclosed file COPYING for license information (LGPL). If you
8
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
10
* @author Mike Cochrane <mike@graftonhall.co.nz>
12
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
15
class Horde_Icalendar_Vtimezone extends Horde_Icalendar
18
* The component type of this class.
22
public $type = 'vTimeZone';
29
public function exportvCalendar()
31
return $this->_exportvData('VTIMEZONE');
35
* Parse child components of the vTimezone component. Returns an
36
* array with the exact time of the time change as well as the
37
* 'from' and 'to' offsets around the change. Time is arbitrarily
38
* based on UTC for comparison.
45
public function parseChild(&$child, $year)
47
// Make sure 'time' key is first for sort().
51
$t = $child->getAttribute('TZOFFSETFROM');
52
} catch (Horde_Icalendar_Exception $e) {
55
$result['from'] = ($t['hour'] * 60 * 60 + $t['minute'] * 60) * ($t['ahead'] ? 1 : -1);
58
$t = $child->getAttribute('TZOFFSETTO');
59
} catch (Horde_Icalendar_Exception $e) {
62
$result['to'] = ($t['hour'] * 60 * 60 + $t['minute'] * 60) * ($t['ahead'] ? 1 : -1);
65
$start = $child->getAttribute('DTSTART');
66
} catch (Horde_Icalendar_Exception $e) {
69
if (!is_int($start)) {
72
$start = getdate($start);
73
if ($start['year'] > $year) {
79
$rdates = $child->getAttributeValues('RDATE');
80
foreach ($rdates as $rdate) {
81
if ($rdate['year'] == $year || $rdate['year'] == $year - 1) {
82
$result['time'] = gmmktime(
83
$start['hours'], $start['minutes'], $start['seconds'],
84
$rdate['month'], $rdate['mday'], $rdate['year']);
88
} catch (Horde_Icalendar_Exception $e) {
92
$rrules = $child->getAttribute('RRULE');
93
} catch (Horde_Icalendar_Exception $e) {
95
$result['time'] = $start[0];
101
$rrules = explode(';', $rrules);
102
foreach ($rrules as $rrule) {
103
$t = explode('=', $rrule);
106
if ($t[1] != 'YEARLY') {
118
$month = intval($t[1]);
122
$len = strspn($t[1], '1234567890-+');
126
$weekday = substr($t[1], $len);
136
$weekday = $weekdays[$weekday];
137
$which = intval(substr($t[1], 0, $len));
141
if (intval($year) > intval(substr($t[1], 0, 4))) {
148
if (empty($month) || !isset($weekday)) {
152
// Get the timestamp for the first day of $month.
153
$when = gmmktime($start['hours'], $start['minutes'], $start['seconds'],
155
// Get the day of the week for the first day of $month.
156
$first_of_month_weekday = intval(gmstrftime('%w', $when));
158
// Go to the first $weekday before first day of $month.
159
if ($weekday >= $first_of_month_weekday) {
162
$when -= ($first_of_month_weekday - $weekday) * 60 * 60 * 24;
164
// If going backwards go to the first $weekday after last day
169
} while (intval(gmstrftime('%m', $when)) == $month);
172
// Calculate $weekday number $which.
173
$when += $which * 60 * 60 * 24 * 7;
175
$result['time'] = $when;
176
$results[] = $result;