annotate plugins/libcalendaring/lib/Sabre/VObject/Property/DateTime.php @ 23:5a851d965bc1

sorting, some better displays
author Charlie Root
date Wed, 17 Jan 2018 09:13:17 -0500
parents 888e774ee983
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1 <?php
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
2
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject\Property;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5 use Sabre\VObject;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 * DateTime property
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 * This element is used for iCalendar properties such as the DTSTART property.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 * It basically provides a few helper functions that make it easier to deal
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 * with these. It supports both DATE-TIME and DATE values.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 * In order to use this correctly, you must call setDateTime and getDateTime to
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 * retrieve and modify dates respectively.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 * If you use the 'value' or properties directly, this object does not keep
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 * reference and results might appear incorrectly.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 * @author Evert Pot (http://evertpot.com/)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 class DateTime extends VObject\Property {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 * Local 'floating' time
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29 const LOCAL = 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 * UTC-based time
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 const UTC = 2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 * Local time plus timezone
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 const LOCALTZ = 3;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42 * Only a date, time is ignored
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 const DATE = 4;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 * DateTime representation
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 * @var \DateTime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 protected $dateTime;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54 * dateType
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56 * @var int
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58 protected $dateType;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 * Updates the Date and Time.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 * @param \DateTime $dt
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64 * @param int $dateType
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67 public function setDateTime(\DateTime $dt, $dateType = self::LOCALTZ) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69 switch($dateType) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71 case self::LOCAL :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72 $this->setValue($dt->format('Ymd\\THis'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73 $this->offsetUnset('VALUE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74 $this->offsetUnset('TZID');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75 $this->offsetSet('VALUE','DATE-TIME');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
76 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
77 case self::UTC :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
78 $dt->setTimeZone(new \DateTimeZone('UTC'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
79 $this->setValue($dt->format('Ymd\\THis\\Z'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
80 $this->offsetUnset('VALUE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
81 $this->offsetUnset('TZID');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
82 $this->offsetSet('VALUE','DATE-TIME');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
83 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
84 case self::LOCALTZ :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
85 $this->setValue($dt->format('Ymd\\THis'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
86 $this->offsetUnset('VALUE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
87 $this->offsetUnset('TZID');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
88 $this->offsetSet('VALUE','DATE-TIME');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
89 $this->offsetSet('TZID', $dt->getTimeZone()->getName());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
90 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
91 case self::DATE :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
92 $this->setValue($dt->format('Ymd'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
93 $this->offsetUnset('VALUE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
94 $this->offsetUnset('TZID');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
95 $this->offsetSet('VALUE','DATE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
96 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
97 default :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
98 throw new \InvalidArgumentException('You must pass a valid dateType constant');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
99
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
100 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
101 $this->dateTime = $dt;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
102 $this->dateType = $dateType;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
103
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
104 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
105
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
106 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
107 * Returns the current DateTime value.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
108 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
109 * If no value was set, this method returns null.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
110 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
111 * @return \DateTime|null
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
112 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
113 public function getDateTime() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
114
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
115 if ($this->dateTime)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
116 return $this->dateTime;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
117
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
118 list(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
119 $this->dateType,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
120 $this->dateTime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
121 ) = self::parseData($this->value, $this);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
122 return $this->dateTime;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
123
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
124 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
125
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
126 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
127 * Returns the type of Date format.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
128 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
129 * This method returns one of the format constants. If no date was set,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
130 * this method will return null.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
131 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
132 * @return int|null
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
133 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
134 public function getDateType() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
135
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
136 if ($this->dateType)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
137 return $this->dateType;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
138
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
139 list(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
140 $this->dateType,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
141 $this->dateTime,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
142 ) = self::parseData($this->value, $this);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
143 return $this->dateType;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
144
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
145 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
146
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
147 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
148 * This method will return true, if the property had a date and a time, as
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
149 * opposed to only a date.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
150 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
151 * @return bool
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
152 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
153 public function hasTime() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
154
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
155 return $this->getDateType()!==self::DATE;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
156
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
157 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
158
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
159 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
160 * Parses the internal data structure to figure out what the current date
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
161 * and time is.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
162 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
163 * The returned array contains two elements:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
164 * 1. A 'DateType' constant (as defined on this class), or null.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
165 * 2. A DateTime object (or null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
166 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
167 * @param string|null $propertyValue The string to parse (yymmdd or
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
168 * ymmddThhmmss, etc..)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
169 * @param \Sabre\VObject\Property|null $property The instance of the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
170 * property we're parsing.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
171 * @return array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
172 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
173 static public function parseData($propertyValue, VObject\Property $property = null) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
174
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
175 if (is_null($propertyValue)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
176 return array(null, null);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
177 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
178
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
179 $date = '(?P<year>[1-2][0-9]{3})(?P<month>[0-1][0-9])(?P<date>[0-3][0-9])';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
180 $time = '(?P<hour>[0-2][0-9])(?P<minute>[0-5][0-9])(?P<second>[0-5][0-9])';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
181 $regex = "/^$date(T$time(?P<isutc>Z)?)?$/";
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
182
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
183 if (!preg_match($regex, $propertyValue, $matches)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
184 throw new \InvalidArgumentException($propertyValue . ' is not a valid \DateTime or Date string');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
185 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
186
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
187 if (!isset($matches['hour'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
188 // Date-only
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
189 return array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
190 self::DATE,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
191 new \DateTime($matches['year'] . '-' . $matches['month'] . '-' . $matches['date'] . ' 00:00:00', new \DateTimeZone('UTC')),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
192 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
193 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
194
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
195 $dateStr =
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
196 $matches['year'] .'-' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
197 $matches['month'] . '-' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
198 $matches['date'] . ' ' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
199 $matches['hour'] . ':' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
200 $matches['minute'] . ':' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
201 $matches['second'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
202
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
203 if (isset($matches['isutc'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
204 $dt = new \DateTime($dateStr,new \DateTimeZone('UTC'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
205 $dt->setTimeZone(new \DateTimeZone('UTC'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
206 return array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
207 self::UTC,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
208 $dt
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
209 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
210 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
211
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
212 // Finding the timezone.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
213 $tzid = $property['TZID'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
214 if (!$tzid) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
215 // This was a floating time string. This implies we use the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
216 // timezone from date_default_timezone_set / date.timezone ini
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
217 // setting.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
218 return array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
219 self::LOCAL,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
220 new \DateTime($dateStr)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
221 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
222 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
223
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
224 // To look up the timezone, we must first find the VCALENDAR component.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
225 $root = $property;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
226 while($root->parent) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
227 $root = $root->parent;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
228 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
229 if ($root->name === 'VCALENDAR') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
230 $tz = VObject\TimeZoneUtil::getTimeZone((string)$tzid, $root);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
231 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
232 $tz = VObject\TimeZoneUtil::getTimeZone((string)$tzid);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
233 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
234
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
235 $dt = new \DateTime($dateStr, $tz);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
236 $dt->setTimeZone($tz);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
237
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
238 return array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
239 self::LOCALTZ,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
240 $dt
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
241 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
242
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
243 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
244
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
245 }