@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | break; |
103 | 103 | default: |
104 | 104 | $this->addCalendarComponentWithKeyAndValue($type, |
105 | - $keyword, |
|
106 | - $value); |
|
105 | + $keyword, |
|
106 | + $value); |
|
107 | 107 | break; |
108 | 108 | } |
109 | 109 | } |
@@ -126,19 +126,19 @@ discard block |
||
126 | 126 | $value) |
127 | 127 | { |
128 | 128 | if (strstr($keyword, ';')) { |
129 | - // Ignore everything in keyword after a ; (things like Language, etc) |
|
130 | - $keyword = substr($keyword, 0, strpos($keyword, ";")); |
|
129 | + // Ignore everything in keyword after a ; (things like Language, etc) |
|
130 | + $keyword = substr($keyword, 0, strpos($keyword, ";")); |
|
131 | 131 | } |
132 | 132 | if ($keyword == false) { |
133 | 133 | $keyword = $this->last_keyword; |
134 | 134 | switch ($component) { |
135 | 135 | case 'VEVENT': |
136 | 136 | $value = $this->cal[$component][$this->event_count - 1] |
137 | - [$keyword].$value; |
|
137 | + [$keyword].$value; |
|
138 | 138 | break; |
139 | 139 | case 'VTODO' : |
140 | 140 | $value = $this->cal[$component][$this->todo_count - 1] |
141 | - [$keyword].$value; |
|
141 | + [$keyword].$value; |
|
142 | 142 | break; |
143 | 143 | } |
144 | 144 | } |
@@ -227,13 +227,13 @@ discard block |
||
227 | 227 | $array = $this->cal; |
228 | 228 | $events = $array['VEVENT']; |
229 | 229 | foreach ($array['VEVENT'] as $anEvent) { |
230 | - if (isset($anEvent['RRULE']) && $anEvent['RRULE'] != '') { |
|
230 | + if (isset($anEvent['RRULE']) && $anEvent['RRULE'] != '') { |
|
231 | 231 | // Recurring event, parse RRULE and add appropriate duplicate events |
232 | 232 | $rrules = array(); |
233 | 233 | $rrule_strings = explode(';',$anEvent['RRULE']); |
234 | 234 | foreach ($rrule_strings as $s) { |
235 | - list($k,$v) = explode('=', $s); |
|
236 | - $rrules[$k] = $v; |
|
235 | + list($k,$v) = explode('=', $s); |
|
236 | + $rrules[$k] = $v; |
|
237 | 237 | } |
238 | 238 | // Get Start timestamp |
239 | 239 | $start_timestamp = $this->iCalDateToUnixTimestamp($anEvent['DTSTART']); |
@@ -245,20 +245,20 @@ discard block |
||
245 | 245 | $until = $this->iCalDateToUnixTimestamp($rrules['UNTIL']); |
246 | 246 | // Decide how often to add events and do so |
247 | 247 | switch ($rrules['FREQ']) { |
248 | - case 'DAILY': |
|
248 | + case 'DAILY': |
|
249 | 249 | // Simply add a new event each interval of days until UNTIL is reached |
250 | 250 | $offset = "+$interval day"; |
251 | 251 | $recurring_timestamp = strtotime($offset, $start_timestamp); |
252 | 252 | while ($recurring_timestamp <= $until) { |
253 | - // Add event |
|
254 | - $anEvent['DTSTART'] = date('Ymd\THis',$recurring_timestamp); |
|
255 | - $anEvent['DTEND'] = date('Ymd\THis',$recurring_timestamp+$event_timestmap_offset); |
|
256 | - $events[] = $anEvent; |
|
257 | - // Move forward |
|
258 | - $recurring_timestamp = strtotime($offset,$recurring_timestamp); |
|
253 | + // Add event |
|
254 | + $anEvent['DTSTART'] = date('Ymd\THis',$recurring_timestamp); |
|
255 | + $anEvent['DTEND'] = date('Ymd\THis',$recurring_timestamp+$event_timestmap_offset); |
|
256 | + $events[] = $anEvent; |
|
257 | + // Move forward |
|
258 | + $recurring_timestamp = strtotime($offset,$recurring_timestamp); |
|
259 | 259 | } |
260 | 260 | break; |
261 | - case 'WEEKLY': |
|
261 | + case 'WEEKLY': |
|
262 | 262 | // Create offset |
263 | 263 | $offset = "+$interval week"; |
264 | 264 | // Build list of days of week to add events |
@@ -268,58 +268,58 @@ discard block |
||
268 | 268 | $week_recurring_timestamp = (date('w', $start_timestamp) == 0) ? $start_timestamp : strtotime('last Sunday '.date('H:i:s',$start_timestamp), $start_timestamp); |
269 | 269 | // Step through weeks |
270 | 270 | while ($week_recurring_timestamp <= $until) { |
271 | - // Add events for bydays |
|
272 | - $day_recurring_timestamp = $week_recurring_timestamp; |
|
273 | - foreach ($weekdays as $day) { |
|
271 | + // Add events for bydays |
|
272 | + $day_recurring_timestamp = $week_recurring_timestamp; |
|
273 | + foreach ($weekdays as $day) { |
|
274 | 274 | // Check if day should be added |
275 | 275 | if (in_array($day, $bydays) && $day_recurring_timestamp > $start_timestamp && $day_recurring_timestamp <= $until) { |
276 | - // Add event to day |
|
277 | - $anEvent['DTSTART'] = date('Ymd\THis',$day_recurring_timestamp); |
|
278 | - $anEvent['DTEND'] = date('Ymd\THis',$day_recurring_timestamp+$event_timestmap_offset); |
|
279 | - $events[] = $anEvent; |
|
276 | + // Add event to day |
|
277 | + $anEvent['DTSTART'] = date('Ymd\THis',$day_recurring_timestamp); |
|
278 | + $anEvent['DTEND'] = date('Ymd\THis',$day_recurring_timestamp+$event_timestmap_offset); |
|
279 | + $events[] = $anEvent; |
|
280 | 280 | } |
281 | 281 | // Move forward a day |
282 | 282 | $day_recurring_timestamp = strtotime('+1 day',$day_recurring_timestamp); |
283 | - } |
|
284 | - // Move forward $interaval weeks |
|
285 | - $week_recurring_timestamp = strtotime($offset,$week_recurring_timestamp); |
|
283 | + } |
|
284 | + // Move forward $interaval weeks |
|
285 | + $week_recurring_timestamp = strtotime($offset,$week_recurring_timestamp); |
|
286 | 286 | } |
287 | 287 | break; |
288 | - case 'MONTHLY': |
|
288 | + case 'MONTHLY': |
|
289 | 289 | // Create offset |
290 | 290 | $offset = "+$interval month"; |
291 | 291 | $recurring_timestamp = strtotime($offset, $start_timestamp); |
292 | 292 | if (isset($rrules['BYMONTHDAY']) && $rrules['BYMONTHDAY'] != '') { |
293 | - // Deal with BYMONTHDAY |
|
294 | - while ($recurring_timestamp <= $until) { |
|
293 | + // Deal with BYMONTHDAY |
|
294 | + while ($recurring_timestamp <= $until) { |
|
295 | 295 | // Add event |
296 | 296 | $anEvent['DTSTART'] = date('Ym'.sprintf('%02d',$rrules['BYMONTHDAY']).'\THis',$recurring_timestamp); |
297 | 297 | $anEvent['DTEND'] = date('Ymd\THis',$this->iCalDateToUnixTimestamp($anEvent['DTSTART'])+$event_timestmap_offset); |
298 | 298 | $events[] = $anEvent; |
299 | 299 | // Move forward |
300 | 300 | $recurring_timestamp = strtotime($offset,$recurring_timestamp); |
301 | - } |
|
301 | + } |
|
302 | 302 | } elseif (isset($rrules['BYDAY']) && $rrules['BYDAY'] != '') { |
303 | - $start_time = date('His',$start_timestamp); |
|
304 | - // Deal with BYDAY |
|
305 | - $day_number = substr($rrules['BYDAY'], 0, 1); |
|
306 | - $week_day = substr($rrules['BYDAY'], 1); |
|
307 | - $day_cardinals = array(1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth'); |
|
308 | - $weekdays = array('SU' => 'sunday','MO' => 'monday','TU' => 'tuesday','WE' => 'wednesday','TH' => 'thursday','FR' => 'friday','SA' => 'saturday'); |
|
309 | - while ($recurring_timestamp <= $until) { |
|
303 | + $start_time = date('His',$start_timestamp); |
|
304 | + // Deal with BYDAY |
|
305 | + $day_number = substr($rrules['BYDAY'], 0, 1); |
|
306 | + $week_day = substr($rrules['BYDAY'], 1); |
|
307 | + $day_cardinals = array(1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth'); |
|
308 | + $weekdays = array('SU' => 'sunday','MO' => 'monday','TU' => 'tuesday','WE' => 'wednesday','TH' => 'thursday','FR' => 'friday','SA' => 'saturday'); |
|
309 | + while ($recurring_timestamp <= $until) { |
|
310 | 310 | $event_start_desc = "{$day_cardinals[$day_number]} {$weekdays[$week_day]} of ".date('F',$recurring_timestamp)." ".date('Y',$recurring_timestamp)." ".date('H:i:s',$recurring_timestamp); |
311 | 311 | $event_start_timestamp = strtotime($event_start_desc); |
312 | 312 | if ($event_start_timestamp > $start_timestamp && $event_start_timestamp < $until) { |
313 | - $anEvent['DTSTART'] = date('Ymd\T',$event_start_timestamp).$start_time; |
|
314 | - $anEvent['DTEND'] = date('Ymd\THis',$this->iCalDateToUnixTimestamp($anEvent['DTSTART'])+$event_timestmap_offset); |
|
315 | - $events[] = $anEvent; |
|
313 | + $anEvent['DTSTART'] = date('Ymd\T',$event_start_timestamp).$start_time; |
|
314 | + $anEvent['DTEND'] = date('Ymd\THis',$this->iCalDateToUnixTimestamp($anEvent['DTSTART'])+$event_timestmap_offset); |
|
315 | + $events[] = $anEvent; |
|
316 | 316 | } |
317 | 317 | // Move forward |
318 | 318 | $recurring_timestamp = strtotime($offset,$recurring_timestamp); |
319 | - } |
|
319 | + } |
|
320 | 320 | } |
321 | 321 | break; |
322 | - case 'YEARLY': |
|
322 | + case 'YEARLY': |
|
323 | 323 | // Create offset |
324 | 324 | $offset = "+$interval year"; |
325 | 325 | $recurring_timestamp = strtotime($offset, $start_timestamp); |
@@ -328,41 +328,41 @@ discard block |
||
328 | 328 | $until = strtotime('+2 year',$start_timestamp); |
329 | 329 | // Check if BYDAY rule exists |
330 | 330 | if (isset($rrules['BYDAY']) && $rrules['BYDAY'] != '') { |
331 | - $start_time = date('His',$start_timestamp); |
|
332 | - // Deal with BYDAY |
|
333 | - $day_number = substr($rrules['BYDAY'], 0, 1); |
|
334 | - $month_day = substr($rrules['BYDAY'], 1); |
|
335 | - $day_cardinals = array(1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth'); |
|
336 | - $weekdays = array('SU' => 'sunday','MO' => 'monday','TU' => 'tuesday','WE' => 'wednesday','TH' => 'thursday','FR' => 'friday','SA' => 'saturday'); |
|
337 | - while ($recurring_timestamp <= $until) { |
|
331 | + $start_time = date('His',$start_timestamp); |
|
332 | + // Deal with BYDAY |
|
333 | + $day_number = substr($rrules['BYDAY'], 0, 1); |
|
334 | + $month_day = substr($rrules['BYDAY'], 1); |
|
335 | + $day_cardinals = array(1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth'); |
|
336 | + $weekdays = array('SU' => 'sunday','MO' => 'monday','TU' => 'tuesday','WE' => 'wednesday','TH' => 'thursday','FR' => 'friday','SA' => 'saturday'); |
|
337 | + while ($recurring_timestamp <= $until) { |
|
338 | 338 | $event_start_desc = "{$day_cardinals[$day_number]} {$weekdays[$month_day]} of {$month_names[$rrules['BYMONTH']]} ".date('Y',$recurring_timestamp)." ".date('H:i:s',$recurring_timestamp); |
339 | 339 | $event_start_timestamp = strtotime($event_start_desc); |
340 | 340 | if ($event_start_timestamp > $start_timestamp && $event_start_timestamp < $until) { |
341 | - $anEvent['DTSTART'] = date('Ymd\T',$event_start_timestamp).$start_time; |
|
342 | - $anEvent['DTEND'] = date('Ymd\THis',$this->iCalDateToUnixTimestamp($anEvent['DTSTART'])+$event_timestmap_offset); |
|
343 | - $events[] = $anEvent; |
|
341 | + $anEvent['DTSTART'] = date('Ymd\T',$event_start_timestamp).$start_time; |
|
342 | + $anEvent['DTEND'] = date('Ymd\THis',$this->iCalDateToUnixTimestamp($anEvent['DTSTART'])+$event_timestmap_offset); |
|
343 | + $events[] = $anEvent; |
|
344 | 344 | } |
345 | 345 | // Move forward |
346 | 346 | $recurring_timestamp = strtotime($offset,$recurring_timestamp); |
347 | - } |
|
347 | + } |
|
348 | 348 | } else { |
349 | - $day = date('d',$start_timestamp); |
|
350 | - // Step throuhg years adding specific month dates |
|
351 | - while ($recurring_timestamp <= $until) { |
|
349 | + $day = date('d',$start_timestamp); |
|
350 | + // Step throuhg years adding specific month dates |
|
351 | + while ($recurring_timestamp <= $until) { |
|
352 | 352 | $event_start_desc = "$day {$month_names[$rrules['BYMONTH']]} ".date('Y',$recurring_timestamp)." ".date('H:i:s',$recurring_timestamp); |
353 | 353 | $event_start_timestamp = strtotime($event_start_desc); |
354 | 354 | if ($event_start_timestamp > $start_timestamp && $event_start_timestamp < $until) { |
355 | - $anEvent['DTSTART'] = date('Ymd\T',$event_start_timestamp).$start_time; |
|
356 | - $anEvent['DTEND'] = date('Ymd\THis',$this->iCalDateToUnixTimestamp($anEvent['DTSTART'])+$event_timestmap_offset); |
|
357 | - $events[] = $anEvent; |
|
355 | + $anEvent['DTSTART'] = date('Ymd\T',$event_start_timestamp).$start_time; |
|
356 | + $anEvent['DTEND'] = date('Ymd\THis',$this->iCalDateToUnixTimestamp($anEvent['DTSTART'])+$event_timestmap_offset); |
|
357 | + $events[] = $anEvent; |
|
358 | 358 | } |
359 | 359 | // Move forward |
360 | 360 | $recurring_timestamp = strtotime($offset,$recurring_timestamp); |
361 | - } |
|
361 | + } |
|
362 | 362 | } |
363 | 363 | break; |
364 | 364 | } |
365 | - } |
|
365 | + } |
|
366 | 366 | } |
367 | 367 | $this->cal['VEVENT'] = $events; |
368 | 368 | } |
@@ -12,26 +12,26 @@ |
||
12 | 12 | |
13 | 13 | class ICalTimeZone |
14 | 14 | { |
15 | - protected $timeZone = 'UTC'; |
|
15 | + protected $timeZone = 'UTC'; |
|
16 | 16 | |
17 | - public function __construct() { |
|
18 | - } |
|
17 | + public function __construct() { |
|
18 | + } |
|
19 | 19 | |
20 | - public function processLine($keyword, $value) { |
|
21 | - if ($keyword == 'TZID') { |
|
22 | - $timezoneIdentifiers = \DateTimeZone::listIdentifiers(); |
|
23 | - if (in_array($value, $timezoneIdentifiers)) { |
|
24 | - $this->timeZone = $value; |
|
25 | - } |
|
26 | - } |
|
27 | - } |
|
20 | + public function processLine($keyword, $value) { |
|
21 | + if ($keyword == 'TZID') { |
|
22 | + $timezoneIdentifiers = \DateTimeZone::listIdentifiers(); |
|
23 | + if (in_array($value, $timezoneIdentifiers)) { |
|
24 | + $this->timeZone = $value; |
|
25 | + } |
|
26 | + } |
|
27 | + } |
|
28 | 28 | |
29 | - public function getTimeZoneIdentifier() { |
|
30 | - return $this->timeZone; |
|
31 | - } |
|
29 | + public function getTimeZoneIdentifier() { |
|
30 | + return $this->timeZone; |
|
31 | + } |
|
32 | 32 | |
33 | - public function getTimeZone() { |
|
34 | - return new \DateTimeZone($this->timeZone); |
|
35 | - } |
|
33 | + public function getTimeZone() { |
|
34 | + return new \DateTimeZone($this->timeZone); |
|
35 | + } |
|
36 | 36 | } |
37 | 37 |
@@ -13,14 +13,14 @@ discard block |
||
13 | 13 | class ICalParser |
14 | 14 | { |
15 | 15 | |
16 | - /** @var ICalTimeZone **/ |
|
17 | - protected $timezone; |
|
16 | + /** @var ICalTimeZone **/ |
|
17 | + protected $timezone; |
|
18 | 18 | |
19 | - protected $events = array(); |
|
19 | + protected $events = array(); |
|
20 | 20 | |
21 | - public function __construct() { |
|
22 | - $this->timezone = new ICalTimeZone(); |
|
23 | - } |
|
21 | + public function __construct() { |
|
22 | + $this->timezone = new ICalTimeZone(); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @param {string} $filename The path to the iCal-file |
@@ -29,90 +29,90 @@ discard block |
||
29 | 29 | public function parseFromFile($filename) |
30 | 30 | { |
31 | 31 | |
32 | - if (!$filename) { |
|
33 | - return false; |
|
34 | - } |
|
32 | + if (!$filename) { |
|
33 | + return false; |
|
34 | + } |
|
35 | 35 | |
36 | - $lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
37 | - if (count($lines) < 1) { |
|
38 | - return false; |
|
39 | - } |
|
36 | + $lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
37 | + if (count($lines) < 1) { |
|
38 | + return false; |
|
39 | + } |
|
40 | 40 | |
41 | 41 | if (stristr($lines[0], 'BEGIN:VCALENDAR') === false) { |
42 | 42 | return false; |
43 | 43 | } else { |
44 | 44 | |
45 | - # pass1: put multi lines back into one line. |
|
46 | - $linesCompacted = array(); |
|
47 | - foreach($lines as $line) { |
|
48 | - if (substr($line,0,1) == ' ') { |
|
49 | - $linesCompacted[count($linesCompacted)-1] .= substr($line, 1); |
|
50 | - } else { |
|
51 | - $linesCompacted[] = trim($line); |
|
52 | - } |
|
53 | - }; |
|
45 | + # pass1: put multi lines back into one line. |
|
46 | + $linesCompacted = array(); |
|
47 | + foreach($lines as $line) { |
|
48 | + if (substr($line,0,1) == ' ') { |
|
49 | + $linesCompacted[count($linesCompacted)-1] .= substr($line, 1); |
|
50 | + } else { |
|
51 | + $linesCompacted[] = trim($line); |
|
52 | + } |
|
53 | + }; |
|
54 | 54 | |
55 | - #pass2: turn lines into formatted data |
|
56 | - $rawLines = array(); |
|
57 | - foreach($linesCompacted as $line) { |
|
58 | - $bits = explode(":", $line, 2); |
|
59 | - $kbits = explode(";", $bits[0], 2); |
|
60 | - $value = count($bits) == 2 ? $bits[1] : ''; |
|
61 | - // http://www.ietf.org/rfc/rfc2445.txt section 4.3.11 |
|
62 | - $value = str_replace('\\\\', '\\', $value); |
|
63 | - $value = str_replace('\\N', "\n", $value); |
|
64 | - $value = str_replace('\\n', "\n", $value); |
|
65 | - $value = str_replace('\\;', ';', $value); |
|
66 | - $value = str_replace('\,', ',', $value); |
|
67 | - $rawLines[] = array( |
|
68 | - 'KEYWORD'=>$kbits[0], |
|
69 | - 'KEYWORDOPTIONS'=>count($kbits) == 2 ? $kbits[1] : '', |
|
70 | - 'VALUE'=>$value, |
|
71 | - ); |
|
72 | - } |
|
55 | + #pass2: turn lines into formatted data |
|
56 | + $rawLines = array(); |
|
57 | + foreach($linesCompacted as $line) { |
|
58 | + $bits = explode(":", $line, 2); |
|
59 | + $kbits = explode(";", $bits[0], 2); |
|
60 | + $value = count($bits) == 2 ? $bits[1] : ''; |
|
61 | + // http://www.ietf.org/rfc/rfc2445.txt section 4.3.11 |
|
62 | + $value = str_replace('\\\\', '\\', $value); |
|
63 | + $value = str_replace('\\N', "\n", $value); |
|
64 | + $value = str_replace('\\n', "\n", $value); |
|
65 | + $value = str_replace('\\;', ';', $value); |
|
66 | + $value = str_replace('\,', ',', $value); |
|
67 | + $rawLines[] = array( |
|
68 | + 'KEYWORD'=>$kbits[0], |
|
69 | + 'KEYWORDOPTIONS'=>count($kbits) == 2 ? $kbits[1] : '', |
|
70 | + 'VALUE'=>$value, |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | - # pass3: finally parse lines |
|
75 | - $stack = array(); |
|
76 | - foreach($rawLines as $line) { |
|
77 | - if ($line['KEYWORD'] == 'BEGIN') { |
|
78 | - $stack[] = $line['VALUE']; |
|
79 | - if ($line['VALUE'] == 'VEVENT') { |
|
80 | - $this->events[] = new ICalEvent($this->timezone->getTimeZone()); |
|
81 | - } |
|
82 | - } else if ($line['KEYWORD'] == 'END') { |
|
83 | - // TODO check VALUE and last stack match |
|
84 | - array_pop($stack); |
|
85 | - } else { |
|
86 | - $currentlyIn = $stack[count($stack)-1]; |
|
87 | - //print $currentlyIn." with K ".$line['KEYWORD']."\n"; |
|
88 | - if ($currentlyIn == 'VEVENT') { |
|
89 | - $this->events[count($this->events)-1]->processLine($line['KEYWORD'],$line['VALUE'], $line['KEYWORDOPTIONS']); |
|
90 | - } elseif ($currentlyIn == 'VTIMEZONE') { |
|
91 | - $this->timezone->processLine($line['KEYWORD'],$line['VALUE'], $line['KEYWORDOPTIONS']); |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
74 | + # pass3: finally parse lines |
|
75 | + $stack = array(); |
|
76 | + foreach($rawLines as $line) { |
|
77 | + if ($line['KEYWORD'] == 'BEGIN') { |
|
78 | + $stack[] = $line['VALUE']; |
|
79 | + if ($line['VALUE'] == 'VEVENT') { |
|
80 | + $this->events[] = new ICalEvent($this->timezone->getTimeZone()); |
|
81 | + } |
|
82 | + } else if ($line['KEYWORD'] == 'END') { |
|
83 | + // TODO check VALUE and last stack match |
|
84 | + array_pop($stack); |
|
85 | + } else { |
|
86 | + $currentlyIn = $stack[count($stack)-1]; |
|
87 | + //print $currentlyIn." with K ".$line['KEYWORD']."\n"; |
|
88 | + if ($currentlyIn == 'VEVENT') { |
|
89 | + $this->events[count($this->events)-1]->processLine($line['KEYWORD'],$line['VALUE'], $line['KEYWORDOPTIONS']); |
|
90 | + } elseif ($currentlyIn == 'VTIMEZONE') { |
|
91 | + $this->timezone->processLine($line['KEYWORD'],$line['VALUE'], $line['KEYWORDOPTIONS']); |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | - //die(); |
|
96 | + //die(); |
|
97 | 97 | |
98 | - return true; |
|
99 | - } |
|
98 | + return true; |
|
99 | + } |
|
100 | 100 | } |
101 | 101 | |
102 | - /** |
|
103 | - * This is only for debugging. |
|
104 | - * This class ensures all dates returned are in UTC, whatever the input time zone was. |
|
105 | - * @return type |
|
106 | - */ |
|
107 | - public function getTimeZoneIdentifier() |
|
108 | - { |
|
109 | - return $this->timezone->getTimeZoneIdentifier(); |
|
110 | - } |
|
102 | + /** |
|
103 | + * This is only for debugging. |
|
104 | + * This class ensures all dates returned are in UTC, whatever the input time zone was. |
|
105 | + * @return type |
|
106 | + */ |
|
107 | + public function getTimeZoneIdentifier() |
|
108 | + { |
|
109 | + return $this->timezone->getTimeZoneIdentifier(); |
|
110 | + } |
|
111 | 111 | |
112 | 112 | public function getEvents() |
113 | 113 | { |
114 | - return $this->events; |
|
115 | - } |
|
114 | + return $this->events; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | } |
118 | 118 |
@@ -13,30 +13,30 @@ |
||
13 | 13 | class ICalExDate |
14 | 14 | { |
15 | 15 | |
16 | - protected $properties; |
|
17 | - protected $values; |
|
18 | - |
|
19 | - function __construct($values, $properties) |
|
20 | - { |
|
21 | - $this->properties = $properties; |
|
22 | - $this->values = $values; |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @return mixed |
|
27 | - */ |
|
28 | - public function getProperties() |
|
29 | - { |
|
30 | - return $this->properties; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return mixed |
|
35 | - */ |
|
36 | - public function getValues() |
|
37 | - { |
|
38 | - return $this->values; |
|
39 | - } |
|
16 | + protected $properties; |
|
17 | + protected $values; |
|
18 | + |
|
19 | + function __construct($values, $properties) |
|
20 | + { |
|
21 | + $this->properties = $properties; |
|
22 | + $this->values = $values; |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @return mixed |
|
27 | + */ |
|
28 | + public function getProperties() |
|
29 | + { |
|
30 | + return $this->properties; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return mixed |
|
35 | + */ |
|
36 | + public function getValues() |
|
37 | + { |
|
38 | + return $this->values; |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | 42 |
@@ -12,91 +12,91 @@ discard block |
||
12 | 12 | class ICalEvent |
13 | 13 | { |
14 | 14 | |
15 | - protected $timeZone; |
|
16 | - protected $timeZoneUTC; |
|
15 | + protected $timeZone; |
|
16 | + protected $timeZoneUTC; |
|
17 | 17 | |
18 | - /** @var \DateTime **/ |
|
19 | - protected $start; |
|
18 | + /** @var \DateTime **/ |
|
19 | + protected $start; |
|
20 | 20 | |
21 | - /** @var \DateTime **/ |
|
22 | - protected $end; |
|
21 | + /** @var \DateTime **/ |
|
22 | + protected $end; |
|
23 | 23 | |
24 | - protected $summary; |
|
24 | + protected $summary; |
|
25 | 25 | |
26 | - protected $location; |
|
26 | + protected $location; |
|
27 | 27 | |
28 | - protected $description; |
|
28 | + protected $description; |
|
29 | 29 | |
30 | - protected $uid; |
|
30 | + protected $uid; |
|
31 | 31 | |
32 | - protected $deleted = false; |
|
32 | + protected $deleted = false; |
|
33 | 33 | |
34 | - protected $url; |
|
34 | + protected $url; |
|
35 | 35 | |
36 | - protected $ical_rrule; |
|
36 | + protected $ical_rrule; |
|
37 | 37 | |
38 | - protected $exdates = array(); |
|
38 | + protected $exdates = array(); |
|
39 | 39 | |
40 | - public function __construct(\DateTimeZone $timeZone = null) { |
|
41 | - $this->timeZoneUTC = new \DateTimeZone('UTC'); |
|
42 | - $this->timeZone = $timeZone ? $timeZone : $this->timeZoneUTC; |
|
43 | - } |
|
40 | + public function __construct(\DateTimeZone $timeZone = null) { |
|
41 | + $this->timeZoneUTC = new \DateTimeZone('UTC'); |
|
42 | + $this->timeZone = $timeZone ? $timeZone : $this->timeZoneUTC; |
|
43 | + } |
|
44 | 44 | |
45 | - public function processLine($keyword, $value, $keywordProperties = "") { |
|
46 | - if ($keyword == 'UID') { |
|
47 | - $this->uid = $value; |
|
48 | - } else if ($keyword == 'LOCATION') { |
|
49 | - $this->location = $value; |
|
50 | - } else if ($keyword == 'SUMMARY') { |
|
51 | - $this->summary = $value; |
|
52 | - } else if ($keyword == 'DESCRIPTION') { |
|
53 | - $this->description = $value; |
|
54 | - } else if ($keyword == 'URL') { |
|
55 | - $this->url = $value; |
|
56 | - } else if ($keyword == 'DTSTART') { |
|
57 | - $this->start = $this->parseDateTime($value, true); |
|
58 | - } else if ($keyword == 'DTEND') { |
|
59 | - $this->end = $this->parseDateTime($value, false); |
|
60 | - } else if ($keyword == 'METHOD' && $value == 'CANCEL') { |
|
61 | - $this->deleted = true; |
|
62 | - } else if ($keyword == 'STATUS' && $value == 'CANCELLED') { |
|
63 | - $this->deleted = true; |
|
64 | - } else if ($keyword == 'RRULE') { |
|
65 | - $rrule = array(); |
|
66 | - foreach(explode(";", $value) as $rruleBit) { |
|
67 | - list($k, $v) = explode("=",$rruleBit,2); |
|
68 | - $rrule[strtoupper($k)] = $v; |
|
69 | - } |
|
70 | - $this->ical_rrule = $rrule; |
|
71 | - } else if ($keyword == "EXDATE") { |
|
72 | - $this->exdates[] = new ICalExDate($value, $keywordProperties); |
|
73 | - } |
|
74 | - |
|
75 | - } |
|
45 | + public function processLine($keyword, $value, $keywordProperties = "") { |
|
46 | + if ($keyword == 'UID') { |
|
47 | + $this->uid = $value; |
|
48 | + } else if ($keyword == 'LOCATION') { |
|
49 | + $this->location = $value; |
|
50 | + } else if ($keyword == 'SUMMARY') { |
|
51 | + $this->summary = $value; |
|
52 | + } else if ($keyword == 'DESCRIPTION') { |
|
53 | + $this->description = $value; |
|
54 | + } else if ($keyword == 'URL') { |
|
55 | + $this->url = $value; |
|
56 | + } else if ($keyword == 'DTSTART') { |
|
57 | + $this->start = $this->parseDateTime($value, true); |
|
58 | + } else if ($keyword == 'DTEND') { |
|
59 | + $this->end = $this->parseDateTime($value, false); |
|
60 | + } else if ($keyword == 'METHOD' && $value == 'CANCEL') { |
|
61 | + $this->deleted = true; |
|
62 | + } else if ($keyword == 'STATUS' && $value == 'CANCELLED') { |
|
63 | + $this->deleted = true; |
|
64 | + } else if ($keyword == 'RRULE') { |
|
65 | + $rrule = array(); |
|
66 | + foreach(explode(";", $value) as $rruleBit) { |
|
67 | + list($k, $v) = explode("=",$rruleBit,2); |
|
68 | + $rrule[strtoupper($k)] = $v; |
|
69 | + } |
|
70 | + $this->ical_rrule = $rrule; |
|
71 | + } else if ($keyword == "EXDATE") { |
|
72 | + $this->exdates[] = new ICalExDate($value, $keywordProperties); |
|
73 | + } |
|
74 | + |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - /* |
|
78 | + /* |
|
79 | 79 | * Based on .... |
80 | 80 | * @author Martin Thoma <[email protected]> |
81 | 81 | * @license http://www.opensource.org/licenses/mit-license.php MIT License |
82 | 82 | * @link http://code.google.com/p/ics-parser/ |
83 | 83 | **/ |
84 | - protected function parseDateTime($value, $isStart) { |
|
84 | + protected function parseDateTime($value, $isStart) { |
|
85 | 85 | $value = str_replace('Z', '', $value); |
86 | - $pattern = '/([0-9]{4})'; // 1: YYYY |
|
86 | + $pattern = '/([0-9]{4})'; // 1: YYYY |
|
87 | 87 | $pattern .= '([0-9]{2})'; // 2: MM |
88 | 88 | $pattern .= '([0-9]{2})'; // 3: DD |
89 | 89 | |
90 | - $hasTimePart = false; |
|
91 | - if (strpos($value, "T") > 1) { |
|
92 | - $value = str_replace('T', '', $value); |
|
93 | - $pattern .= '([0-9]{0,2})'; // 4: HH |
|
94 | - $pattern .= '([0-9]{0,2})'; // 5: MM |
|
95 | - $pattern .= '([0-9]{0,2})/'; // 6: SS |
|
96 | - $hasTimePart = true; |
|
97 | - } else { |
|
98 | - $pattern .= '/'; |
|
99 | - } |
|
90 | + $hasTimePart = false; |
|
91 | + if (strpos($value, "T") > 1) { |
|
92 | + $value = str_replace('T', '', $value); |
|
93 | + $pattern .= '([0-9]{0,2})'; // 4: HH |
|
94 | + $pattern .= '([0-9]{0,2})'; // 5: MM |
|
95 | + $pattern .= '([0-9]{0,2})/'; // 6: SS |
|
96 | + $hasTimePart = true; |
|
97 | + } else { |
|
98 | + $pattern .= '/'; |
|
99 | + } |
|
100 | 100 | preg_match($pattern, $value, $date); |
101 | 101 | |
102 | 102 | // Unix timestamp can't represent dates before 1970 |
@@ -106,90 +106,90 @@ discard block |
||
106 | 106 | // Unix timestamps after 03:14:07 UTC 2038-01-19 might cause an overflow |
107 | 107 | // if 32 bit integers are used. |
108 | 108 | |
109 | - $out = new \DateTime('', $this->timeZone); |
|
110 | - $out->setDate((int)$date[1], (int)$date[2], (int)$date[3]); |
|
111 | - if ($hasTimePart) { |
|
112 | - $out->setTime((int)$date[4], (int)$date[5], (int)$date[6]); |
|
113 | - } else if ($isStart) { |
|
114 | - $out->setTime(0,0,0); |
|
115 | - } else if (!$isStart) { |
|
116 | - $out->setTime(23,59,59); |
|
117 | - } |
|
118 | - if ($this->timeZone->getName() != 'UTC') { |
|
119 | - $out->setTimezone($this->timeZoneUTC); |
|
120 | - } |
|
121 | - return $out; |
|
122 | - } |
|
109 | + $out = new \DateTime('', $this->timeZone); |
|
110 | + $out->setDate((int)$date[1], (int)$date[2], (int)$date[3]); |
|
111 | + if ($hasTimePart) { |
|
112 | + $out->setTime((int)$date[4], (int)$date[5], (int)$date[6]); |
|
113 | + } else if ($isStart) { |
|
114 | + $out->setTime(0,0,0); |
|
115 | + } else if (!$isStart) { |
|
116 | + $out->setTime(23,59,59); |
|
117 | + } |
|
118 | + if ($this->timeZone->getName() != 'UTC') { |
|
119 | + $out->setTimezone($this->timeZoneUTC); |
|
120 | + } |
|
121 | + return $out; |
|
122 | + } |
|
123 | 123 | |
124 | 124 | |
125 | - public function getUid() { |
|
126 | - return $this->uid; |
|
127 | - } |
|
125 | + public function getUid() { |
|
126 | + return $this->uid; |
|
127 | + } |
|
128 | 128 | |
129 | - public function setUid($uid) { |
|
130 | - $this->uid = $uid; |
|
131 | - } |
|
129 | + public function setUid($uid) { |
|
130 | + $this->uid = $uid; |
|
131 | + } |
|
132 | 132 | |
133 | - public function getStart() { |
|
134 | - return $this->start; |
|
135 | - } |
|
133 | + public function getStart() { |
|
134 | + return $this->start; |
|
135 | + } |
|
136 | 136 | |
137 | - public function getEnd() { |
|
138 | - return $this->end; |
|
139 | - } |
|
137 | + public function getEnd() { |
|
138 | + return $this->end; |
|
139 | + } |
|
140 | 140 | |
141 | - public function getSummary() { |
|
142 | - return $this->summary; |
|
143 | - } |
|
141 | + public function getSummary() { |
|
142 | + return $this->summary; |
|
143 | + } |
|
144 | 144 | |
145 | - public function getLocation() { |
|
146 | - return $this->location; |
|
147 | - } |
|
145 | + public function getLocation() { |
|
146 | + return $this->location; |
|
147 | + } |
|
148 | 148 | |
149 | - public function getDescription() { |
|
150 | - return $this->description; |
|
151 | - } |
|
149 | + public function getDescription() { |
|
150 | + return $this->description; |
|
151 | + } |
|
152 | 152 | |
153 | - public function getUrl() { |
|
154 | - return $this->url; |
|
155 | - } |
|
156 | - |
|
157 | - public function isDeleted() { |
|
158 | - return $this->deleted; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public function getRRule() |
|
165 | - { |
|
166 | - return $this->ical_rrule; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @return array |
|
171 | - */ |
|
172 | - public function getExDates() |
|
173 | - { |
|
174 | - return $this->exdates; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * @return ICalExDate |
|
179 | - */ |
|
180 | - public function getExDate($position) |
|
181 | - { |
|
182 | - return $this->exdates[$position]; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @return integer |
|
188 | - */ |
|
189 | - public function getExDatesCount() |
|
190 | - { |
|
191 | - return count($this->exdates); |
|
192 | - } |
|
153 | + public function getUrl() { |
|
154 | + return $this->url; |
|
155 | + } |
|
156 | + |
|
157 | + public function isDeleted() { |
|
158 | + return $this->deleted; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public function getRRule() |
|
165 | + { |
|
166 | + return $this->ical_rrule; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @return array |
|
171 | + */ |
|
172 | + public function getExDates() |
|
173 | + { |
|
174 | + return $this->exdates; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * @return ICalExDate |
|
179 | + */ |
|
180 | + public function getExDate($position) |
|
181 | + { |
|
182 | + return $this->exdates[$position]; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @return integer |
|
188 | + */ |
|
189 | + public function getExDatesCount() |
|
190 | + { |
|
191 | + return count($this->exdates); |
|
192 | + } |
|
193 | 193 | |
194 | 194 | |
195 | 195 |
@@ -13,25 +13,25 @@ |
||
13 | 13 | |
14 | 14 | |
15 | 15 | |
16 | - function dataForTestMultiLineDescription() { |
|
17 | - return array( |
|
18 | - array('IcalParserBasicImportMultiLineDescription.ical','Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Lizard'), |
|
19 | - array('IcalParserBasicImportMultiLineDescription2.ical','Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Lizard:Blue'), |
|
20 | - array('IcalParserBasicImportMultiLineDescription3.ical','Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Go Miaow Lizard:Blue abcdefgtijklmnopqrstuvwxyz abcdefgtijklmnopqrstuvwxyz 12345'), |
|
21 | - ); |
|
22 | - } |
|
23 | - |
|
24 | - /** |
|
16 | + function dataForTestMultiLineDescription() { |
|
17 | + return array( |
|
18 | + array('IcalParserBasicImportMultiLineDescription.ical','Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Lizard'), |
|
19 | + array('IcalParserBasicImportMultiLineDescription2.ical','Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Lizard:Blue'), |
|
20 | + array('IcalParserBasicImportMultiLineDescription3.ical','Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Dog Cat Go Miaow Lizard:Blue abcdefgtijklmnopqrstuvwxyz abcdefgtijklmnopqrstuvwxyz 12345'), |
|
21 | + ); |
|
22 | + } |
|
23 | + |
|
24 | + /** |
|
25 | 25 | * @dataProvider dataForTestMultiLineDescription |
26 | 26 | */ |
27 | - function testMultiLineDescription ($filename, $output) { |
|
28 | - $parser = new ICalParser(); |
|
29 | - $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/".$filename)); |
|
30 | - $events = $parser->getEvents(); |
|
31 | - $this->assertEquals(1, count($events)); |
|
32 | - $event = $events[0]; |
|
33 | - $this->assertEquals($output, $event->getDescription()); |
|
34 | - } |
|
27 | + function testMultiLineDescription ($filename, $output) { |
|
28 | + $parser = new ICalParser(); |
|
29 | + $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/".$filename)); |
|
30 | + $events = $parser->getEvents(); |
|
31 | + $this->assertEquals(1, count($events)); |
|
32 | + $event = $events[0]; |
|
33 | + $this->assertEquals($output, $event->getDescription()); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | 37 |
@@ -14,46 +14,46 @@ |
||
14 | 14 | |
15 | 15 | |
16 | 16 | |
17 | - function dataForTestRRule() { |
|
18 | - return array( |
|
19 | - array('IcalParserRRule1.ics',array("FREQ"=>"WEEKLY","BYDAY"=>"WE")), |
|
20 | - array('IcalParserRRule2.ics',array("FREQ"=>"WEEKLY","BYDAY"=>"TH","COUNT"=>5)), |
|
21 | - ); |
|
22 | - } |
|
23 | - |
|
24 | - /** |
|
25 | - * @dataProvider dataForTestRRule |
|
26 | - */ |
|
27 | - function testGetByPosition ($filename, $rrule) { |
|
28 | - $parser = new ICalParser(); |
|
29 | - $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/".$filename)); |
|
30 | - $events = $parser->getEvents(); |
|
31 | - $this->assertEquals(1, count($events)); |
|
32 | - $event = $events[0]; |
|
33 | - |
|
34 | - $eventRRule = $event->getRrule(); |
|
35 | - $this->assertEquals(count(array_keys($rrule)), count(array_keys($eventRRule))); |
|
36 | - foreach($rrule as $k=>$v) { |
|
37 | - $this->assertEquals($v, $eventRRule[$k]); |
|
38 | - } |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @dataProvider dataForTestRRule |
|
43 | - */ |
|
44 | - function testGetByArray ($filename, $rrule) { |
|
45 | - $parser = new ICalParser(); |
|
46 | - $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/".$filename)); |
|
47 | - $events = $parser->getEvents(); |
|
48 | - $this->assertEquals(1, count($events)); |
|
49 | - $event = $events[0]; |
|
50 | - |
|
51 | - $eventRRule = $event->getRrule(); |
|
52 | - $this->assertEquals(count(array_keys($rrule)), count(array_keys($eventRRule))); |
|
53 | - foreach($rrule as $k=>$v) { |
|
54 | - $this->assertEquals($v, $eventRRule[$k]); |
|
55 | - } |
|
56 | - } |
|
17 | + function dataForTestRRule() { |
|
18 | + return array( |
|
19 | + array('IcalParserRRule1.ics',array("FREQ"=>"WEEKLY","BYDAY"=>"WE")), |
|
20 | + array('IcalParserRRule2.ics',array("FREQ"=>"WEEKLY","BYDAY"=>"TH","COUNT"=>5)), |
|
21 | + ); |
|
22 | + } |
|
23 | + |
|
24 | + /** |
|
25 | + * @dataProvider dataForTestRRule |
|
26 | + */ |
|
27 | + function testGetByPosition ($filename, $rrule) { |
|
28 | + $parser = new ICalParser(); |
|
29 | + $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/".$filename)); |
|
30 | + $events = $parser->getEvents(); |
|
31 | + $this->assertEquals(1, count($events)); |
|
32 | + $event = $events[0]; |
|
33 | + |
|
34 | + $eventRRule = $event->getRrule(); |
|
35 | + $this->assertEquals(count(array_keys($rrule)), count(array_keys($eventRRule))); |
|
36 | + foreach($rrule as $k=>$v) { |
|
37 | + $this->assertEquals($v, $eventRRule[$k]); |
|
38 | + } |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @dataProvider dataForTestRRule |
|
43 | + */ |
|
44 | + function testGetByArray ($filename, $rrule) { |
|
45 | + $parser = new ICalParser(); |
|
46 | + $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/".$filename)); |
|
47 | + $events = $parser->getEvents(); |
|
48 | + $this->assertEquals(1, count($events)); |
|
49 | + $event = $events[0]; |
|
50 | + |
|
51 | + $eventRRule = $event->getRrule(); |
|
52 | + $this->assertEquals(count(array_keys($rrule)), count(array_keys($eventRRule))); |
|
53 | + foreach($rrule as $k=>$v) { |
|
54 | + $this->assertEquals($v, $eventRRule[$k]); |
|
55 | + } |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | 59 |
@@ -12,30 +12,30 @@ |
||
12 | 12 | class ExDateTest extends \PHPUnit_Framework_TestCase { |
13 | 13 | |
14 | 14 | |
15 | - function test1 () { |
|
16 | - $parser = new ICalParser(); |
|
17 | - $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/exdate1.ics")); |
|
18 | - $events = $parser->getEvents(); |
|
19 | - $this->assertEquals(1, count($events)); |
|
20 | - |
|
21 | - /** @var $event ICalEvent */ |
|
22 | - $event = $events[0]; |
|
23 | - |
|
24 | - $eventRRule = $event->getRrule(); |
|
25 | - $rrule = array("FREQ"=>"WEEKLY","INTERVAL"=>"2","BYDAY"=>"TH"); |
|
26 | - $this->assertEquals(count(array_keys($rrule)), count(array_keys($eventRRule))); |
|
27 | - foreach($rrule as $k=>$v) { |
|
28 | - $this->assertEquals($v, $eventRRule[$k]); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - $this->assertEquals(1, $event->getExDatesCount()); |
|
33 | - /** @var $exdate ICalExDate */ |
|
34 | - $exdate = $event->getExDate(0); |
|
35 | - $this->assertEquals("TZID=Europe/London",$exdate->getProperties()); |
|
36 | - $this->assertEquals("20150226T090000",$exdate->getValues()); |
|
37 | - |
|
38 | - } |
|
15 | + function test1 () { |
|
16 | + $parser = new ICalParser(); |
|
17 | + $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/exdate1.ics")); |
|
18 | + $events = $parser->getEvents(); |
|
19 | + $this->assertEquals(1, count($events)); |
|
20 | + |
|
21 | + /** @var $event ICalEvent */ |
|
22 | + $event = $events[0]; |
|
23 | + |
|
24 | + $eventRRule = $event->getRrule(); |
|
25 | + $rrule = array("FREQ"=>"WEEKLY","INTERVAL"=>"2","BYDAY"=>"TH"); |
|
26 | + $this->assertEquals(count(array_keys($rrule)), count(array_keys($eventRRule))); |
|
27 | + foreach($rrule as $k=>$v) { |
|
28 | + $this->assertEquals($v, $eventRRule[$k]); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + $this->assertEquals(1, $event->getExDatesCount()); |
|
33 | + /** @var $exdate ICalExDate */ |
|
34 | + $exdate = $event->getExDate(0); |
|
35 | + $this->assertEquals("TZID=Europe/London",$exdate->getProperties()); |
|
36 | + $this->assertEquals("20150226T090000",$exdate->getValues()); |
|
37 | + |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | 41 |
@@ -11,22 +11,22 @@ |
||
11 | 11 | */ |
12 | 12 | class TimezoneTest extends \PHPUnit_Framework_TestCase { |
13 | 13 | |
14 | - function dataForTestTimeZone1() { |
|
15 | - return array( |
|
16 | - array('London.ical','Europe/London'), |
|
17 | - array('UTC.ical','UTC'), |
|
18 | - array('BasicICAL.ical','UTC'), |
|
19 | - ); |
|
20 | - } |
|
14 | + function dataForTestTimeZone1() { |
|
15 | + return array( |
|
16 | + array('London.ical','Europe/London'), |
|
17 | + array('UTC.ical','UTC'), |
|
18 | + array('BasicICAL.ical','UTC'), |
|
19 | + ); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
22 | + /** |
|
23 | 23 | * @dataProvider dataForTestTimeZone1 |
24 | 24 | */ |
25 | - function testTimeZone1 ($filename, $timeZone) { |
|
26 | - $parser = new ICalParser(); |
|
27 | - $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/".$filename)); |
|
28 | - $this->assertEquals($timeZone, $parser->getTimeZoneIdentifier()); |
|
29 | - } |
|
25 | + function testTimeZone1 ($filename, $timeZone) { |
|
26 | + $parser = new ICalParser(); |
|
27 | + $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/".$filename)); |
|
28 | + $this->assertEquals($timeZone, $parser->getTimeZoneIdentifier()); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | } |
32 | 32 |