3 class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
5 function testValues() {
7 $ev = new Sabre_VObject_Component('VEVENT');
9 $ev->RRULE = 'FREQ=DAILY;BYHOUR=10;BYMINUTE=5;BYSECOND=16;BYWEEKNO=32;BYYEARDAY=100,200';
10 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
11 $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
15 $vcal = Sabre_VObject_Component::create('VCALENDAR');
18 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
20 $this->assertEquals(array(10), $it->byHour);
21 $this->assertEquals(array(5), $it->byMinute);
22 $this->assertEquals(array(16), $it->bySecond);
23 $this->assertEquals(array(32), $it->byWeekNo);
24 $this->assertEquals(array(100,200), $it->byYearDay);
29 * @expectedException InvalidArgumentException
32 function testInvalidFreq() {
34 $ev = new Sabre_VObject_Component('VEVENT');
35 $ev->RRULE = 'FREQ=SMONTHLY;INTERVAL=3;UNTIL=20111025T000000Z';
36 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
37 $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
41 $vcal = Sabre_VObject_Component::create('VCALENDAR');
44 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
49 * @expectedException InvalidArgumentException
51 function testVCalendarNoUID() {
53 $vcal = new Sabre_VObject_Component('VCALENDAR');
54 $it = new Sabre_VObject_RecurrenceIterator($vcal);
59 * @expectedException InvalidArgumentException
61 function testVCalendarInvalidUID() {
63 $vcal = new Sabre_VObject_Component('VCALENDAR');
64 $it = new Sabre_VObject_RecurrenceIterator($vcal,'foo');
71 function testDaily() {
73 $ev = new Sabre_VObject_Component('VEVENT');
75 $ev->RRULE = 'FREQ=DAILY;INTERVAL=3;UNTIL=20111025T000000Z';
76 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
77 $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
81 $vcal = Sabre_VObject_Component::create('VCALENDAR');
84 $it = new Sabre_VObject_RecurrenceIterator($vcal,$ev->uid);
86 $this->assertEquals('daily', $it->frequency);
87 $this->assertEquals(3, $it->interval);
88 $this->assertEquals(new DateTime('2011-10-25', new DateTimeZone('UTC')), $it->until);
90 // Max is to prevent overflow
93 foreach($it as $item) {
102 $tz = new DateTimeZone('UTC');
106 new DateTime('2011-10-07', $tz),
107 new DateTime('2011-10-10', $tz),
108 new DateTime('2011-10-13', $tz),
109 new DateTime('2011-10-16', $tz),
110 new DateTime('2011-10-19', $tz),
111 new DateTime('2011-10-22', $tz),
112 new DateTime('2011-10-25', $tz),
120 * @depends testValues
122 function testNoRRULE() {
124 $ev = new Sabre_VObject_Component('VEVENT');
126 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
127 $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
131 $vcal = Sabre_VObject_Component::create('VCALENDAR');
134 $it = new Sabre_VObject_RecurrenceIterator($vcal,$ev->uid);
136 $this->assertEquals('daily', $it->frequency);
137 $this->assertEquals(1, $it->interval);
139 // Max is to prevent overflow
142 foreach($it as $item) {
151 $tz = new DateTimeZone('UTC');
155 new DateTime('2011-10-07', $tz),
163 * @depends testValues
165 function testDailyByDay() {
167 $ev = new Sabre_VObject_Component('VEVENT');
169 $ev->RRULE = 'FREQ=DAILY;INTERVAL=2;BYDAY=TU,WE,FR';
170 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
171 $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
175 $vcal = Sabre_VObject_Component::create('VCALENDAR');
178 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
180 $this->assertEquals('daily', $it->frequency);
181 $this->assertEquals(2, $it->interval);
182 $this->assertEquals(array('TU','WE','FR'), $it->byDay);
184 // Grabbing the next 12 items
187 foreach($it as $item) {
196 $tz = new DateTimeZone('UTC');
200 new DateTime('2011-10-07', $tz),
201 new DateTime('2011-10-11', $tz),
202 new DateTime('2011-10-19', $tz),
203 new DateTime('2011-10-21', $tz),
204 new DateTime('2011-10-25', $tz),
205 new DateTime('2011-11-02', $tz),
206 new DateTime('2011-11-04', $tz),
207 new DateTime('2011-11-08', $tz),
208 new DateTime('2011-11-16', $tz),
209 new DateTime('2011-11-18', $tz),
210 new DateTime('2011-11-22', $tz),
211 new DateTime('2011-11-30', $tz),
219 * @depends testValues
221 function testWeekly() {
223 $ev = new Sabre_VObject_Component('VEVENT');
225 $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;COUNT=10';
226 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
227 $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
231 $vcal = Sabre_VObject_Component::create('VCALENDAR');
234 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
236 $this->assertEquals('weekly', $it->frequency);
237 $this->assertEquals(2, $it->interval);
238 $this->assertEquals(10, $it->count);
240 // Max is to prevent overflow
243 foreach($it as $item) {
252 $tz = new DateTimeZone('UTC');
256 new DateTime('2011-10-07', $tz),
257 new DateTime('2011-10-21', $tz),
258 new DateTime('2011-11-04', $tz),
259 new DateTime('2011-11-18', $tz),
260 new DateTime('2011-12-02', $tz),
261 new DateTime('2011-12-16', $tz),
262 new DateTime('2011-12-30', $tz),
263 new DateTime('2012-01-13', $tz),
264 new DateTime('2012-01-27', $tz),
265 new DateTime('2012-02-10', $tz),
273 * @depends testValues
275 function testWeeklyByDay() {
277 $ev = new Sabre_VObject_Component('VEVENT');
279 $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU';
280 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
281 $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
285 $vcal = Sabre_VObject_Component::create('VCALENDAR');
288 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
290 $this->assertEquals('weekly', $it->frequency);
291 $this->assertEquals(2, $it->interval);
292 $this->assertEquals(array('TU','WE','FR'), $it->byDay);
293 $this->assertEquals('SU', $it->weekStart);
295 // Grabbing the next 12 items
298 foreach($it as $item) {
307 $tz = new DateTimeZone('UTC');
311 new DateTime('2011-10-07', $tz),
312 new DateTime('2011-10-18', $tz),
313 new DateTime('2011-10-19', $tz),
314 new DateTime('2011-10-21', $tz),
315 new DateTime('2011-11-01', $tz),
316 new DateTime('2011-11-02', $tz),
317 new DateTime('2011-11-04', $tz),
318 new DateTime('2011-11-15', $tz),
319 new DateTime('2011-11-16', $tz),
320 new DateTime('2011-11-18', $tz),
321 new DateTime('2011-11-29', $tz),
322 new DateTime('2011-11-30', $tz),
330 * @depends testValues
332 function testMonthly() {
334 $ev = new Sabre_VObject_Component('VEVENT');
336 $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=3;COUNT=5';
337 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
338 $dtStart->setDateTime(new DateTime('2011-12-05'),Sabre_VObject_Property_DateTime::UTC);
342 $vcal = Sabre_VObject_Component::create('VCALENDAR');
345 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
347 $this->assertEquals('monthly', $it->frequency);
348 $this->assertEquals(3, $it->interval);
349 $this->assertEquals(5, $it->count);
353 foreach($it as $item) {
362 $tz = new DateTimeZone('UTC');
366 new DateTime('2011-12-05', $tz),
367 new DateTime('2012-03-05', $tz),
368 new DateTime('2012-06-05', $tz),
369 new DateTime('2012-09-05', $tz),
370 new DateTime('2012-12-05', $tz),
379 * @depends testValues
381 function testMonthlyEndOfMonth() {
383 $ev = new Sabre_VObject_Component('VEVENT');
385 $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=12';
386 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
387 $dtStart->setDateTime(new DateTime('2011-12-31'),Sabre_VObject_Property_DateTime::UTC);
391 $vcal = Sabre_VObject_Component::create('VCALENDAR');
394 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
396 $this->assertEquals('monthly', $it->frequency);
397 $this->assertEquals(2, $it->interval);
398 $this->assertEquals(12, $it->count);
402 foreach($it as $item) {
411 $tz = new DateTimeZone('UTC');
415 new DateTime('2011-12-31', $tz),
416 new DateTime('2012-08-31', $tz),
417 new DateTime('2012-10-31', $tz),
418 new DateTime('2012-12-31', $tz),
419 new DateTime('2013-08-31', $tz),
420 new DateTime('2013-10-31', $tz),
421 new DateTime('2013-12-31', $tz),
422 new DateTime('2014-08-31', $tz),
423 new DateTime('2014-10-31', $tz),
424 new DateTime('2014-12-31', $tz),
425 new DateTime('2015-08-31', $tz),
426 new DateTime('2015-10-31', $tz),
435 * @depends testValues
437 function testMonthlyByMonthDay() {
439 $ev = new Sabre_VObject_Component('VEVENT');
441 $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=5;COUNT=9;BYMONTHDAY=1,31,-7';
442 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
443 $dtStart->setDateTime(new DateTime('2011-01-01'),Sabre_VObject_Property_DateTime::UTC);
447 $vcal = Sabre_VObject_Component::create('VCALENDAR');
450 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
452 $this->assertEquals('monthly', $it->frequency);
453 $this->assertEquals(5, $it->interval);
454 $this->assertEquals(9, $it->count);
455 $this->assertEquals(array(1, 31, -7), $it->byMonthDay);
459 foreach($it as $item) {
468 $tz = new DateTimeZone('UTC');
472 new DateTime('2011-01-01', $tz),
473 new DateTime('2011-01-25', $tz),
474 new DateTime('2011-01-31', $tz),
475 new DateTime('2011-06-01', $tz),
476 new DateTime('2011-06-24', $tz),
477 new DateTime('2011-11-01', $tz),
478 new DateTime('2011-11-24', $tz),
479 new DateTime('2012-04-01', $tz),
480 new DateTime('2012-04-24', $tz),
488 * @depends testValues
490 function testMonthlyByDay() {
492 $ev = new Sabre_VObject_Component('VEVENT');
494 $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=16;BYDAY=MO,-2TU,+1WE,3TH';
495 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
496 $dtStart->setDateTime(new DateTime('2011-01-03'),Sabre_VObject_Property_DateTime::UTC);
500 $vcal = Sabre_VObject_Component::create('VCALENDAR');
503 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
505 $this->assertEquals('monthly', $it->frequency);
506 $this->assertEquals(2, $it->interval);
507 $this->assertEquals(16, $it->count);
508 $this->assertEquals(array('MO','-2TU','+1WE','3TH'), $it->byDay);
512 foreach($it as $k=>$item) {
521 $tz = new DateTimeZone('UTC');
525 new DateTime('2011-01-03', $tz),
526 new DateTime('2011-01-05', $tz),
527 new DateTime('2011-01-10', $tz),
528 new DateTime('2011-01-17', $tz),
529 new DateTime('2011-01-18', $tz),
530 new DateTime('2011-01-20', $tz),
531 new DateTime('2011-01-24', $tz),
532 new DateTime('2011-01-31', $tz),
533 new DateTime('2011-03-02', $tz),
534 new DateTime('2011-03-07', $tz),
535 new DateTime('2011-03-14', $tz),
536 new DateTime('2011-03-17', $tz),
537 new DateTime('2011-03-21', $tz),
538 new DateTime('2011-03-22', $tz),
539 new DateTime('2011-03-28', $tz),
540 new DateTime('2011-05-02', $tz),
548 * @depends testValues
550 function testMonthlyByDayByMonthDay() {
552 $ev = new Sabre_VObject_Component('VEVENT');
554 $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO;BYMONTHDAY=1';
555 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
556 $dtStart->setDateTime(new DateTime('2011-08-01'),Sabre_VObject_Property_DateTime::UTC);
560 $vcal = Sabre_VObject_Component::create('VCALENDAR');
563 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
565 $this->assertEquals('monthly', $it->frequency);
566 $this->assertEquals(1, $it->interval);
567 $this->assertEquals(10, $it->count);
568 $this->assertEquals(array('MO'), $it->byDay);
569 $this->assertEquals(array(1), $it->byMonthDay);
573 foreach($it as $k=>$item) {
582 $tz = new DateTimeZone('UTC');
586 new DateTime('2011-08-01', $tz),
587 new DateTime('2012-10-01', $tz),
588 new DateTime('2013-04-01', $tz),
589 new DateTime('2013-07-01', $tz),
590 new DateTime('2014-09-01', $tz),
591 new DateTime('2014-12-01', $tz),
592 new DateTime('2015-06-01', $tz),
593 new DateTime('2016-02-01', $tz),
594 new DateTime('2016-08-01', $tz),
595 new DateTime('2017-05-01', $tz),
603 * @depends testValues
605 function testMonthlyByDayBySetPos() {
607 $ev = new Sabre_VObject_Component('VEVENT');
609 $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1';
610 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
611 $dtStart->setDateTime(new DateTime('2011-01-03'),Sabre_VObject_Property_DateTime::UTC);
615 $vcal = Sabre_VObject_Component::create('VCALENDAR');
618 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
620 $this->assertEquals('monthly', $it->frequency);
621 $this->assertEquals(1, $it->interval);
622 $this->assertEquals(10, $it->count);
623 $this->assertEquals(array('MO','TU','WE','TH','FR'), $it->byDay);
624 $this->assertEquals(array(1,-1), $it->bySetPos);
628 foreach($it as $k=>$item) {
637 $tz = new DateTimeZone('UTC');
641 new DateTime('2011-01-03', $tz),
642 new DateTime('2011-01-31', $tz),
643 new DateTime('2011-02-01', $tz),
644 new DateTime('2011-02-28', $tz),
645 new DateTime('2011-03-01', $tz),
646 new DateTime('2011-03-31', $tz),
647 new DateTime('2011-04-01', $tz),
648 new DateTime('2011-04-29', $tz),
649 new DateTime('2011-05-02', $tz),
650 new DateTime('2011-05-31', $tz),
658 * @depends testValues
660 function testYearly() {
662 $ev = new Sabre_VObject_Component('VEVENT');
664 $ev->RRULE = 'FREQ=YEARLY;COUNT=10;INTERVAL=3';
665 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
666 $dtStart->setDateTime(new DateTime('2011-01-01'),Sabre_VObject_Property_DateTime::UTC);
670 $vcal = Sabre_VObject_Component::create('VCALENDAR');
673 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
675 $this->assertEquals('yearly', $it->frequency);
676 $this->assertEquals(3, $it->interval);
677 $this->assertEquals(10, $it->count);
681 foreach($it as $k=>$item) {
690 $tz = new DateTimeZone('UTC');
694 new DateTime('2011-01-01', $tz),
695 new DateTime('2014-01-01', $tz),
696 new DateTime('2017-01-01', $tz),
697 new DateTime('2020-01-01', $tz),
698 new DateTime('2023-01-01', $tz),
699 new DateTime('2026-01-01', $tz),
700 new DateTime('2029-01-01', $tz),
701 new DateTime('2032-01-01', $tz),
702 new DateTime('2035-01-01', $tz),
703 new DateTime('2038-01-01', $tz),
711 * @depends testValues
713 function testYearlyByMonth() {
715 $ev = new Sabre_VObject_Component('VEVENT');
717 $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYMONTH=4,10';
718 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
719 $dtStart->setDateTime(new DateTime('2011-04-07'),Sabre_VObject_Property_DateTime::UTC);
723 $vcal = Sabre_VObject_Component::create('VCALENDAR');
726 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
728 $this->assertEquals('yearly', $it->frequency);
729 $this->assertEquals(4, $it->interval);
730 $this->assertEquals(8, $it->count);
731 $this->assertEquals(array(4,10), $it->byMonth);
735 foreach($it as $k=>$item) {
744 $tz = new DateTimeZone('UTC');
748 new DateTime('2011-04-07', $tz),
749 new DateTime('2011-10-07', $tz),
750 new DateTime('2015-04-07', $tz),
751 new DateTime('2015-10-07', $tz),
752 new DateTime('2019-04-07', $tz),
753 new DateTime('2019-10-07', $tz),
754 new DateTime('2023-04-07', $tz),
755 new DateTime('2023-10-07', $tz),
763 * @depends testValues
765 function testYearlyByMonthByDay() {
767 $ev = new Sabre_VObject_Component('VEVENT');
769 $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU';
770 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
771 $dtStart->setDateTime(new DateTime('2011-04-04'),Sabre_VObject_Property_DateTime::UTC);
775 $vcal = Sabre_VObject_Component::create('VCALENDAR');
778 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
780 $this->assertEquals('yearly', $it->frequency);
781 $this->assertEquals(5, $it->interval);
782 $this->assertEquals(8, $it->count);
783 $this->assertEquals(array(4,10), $it->byMonth);
784 $this->assertEquals(array('1MO','-1SU'), $it->byDay);
788 foreach($it as $k=>$item) {
797 $tz = new DateTimeZone('UTC');
801 new DateTime('2011-04-04', $tz),
802 new DateTime('2011-04-24', $tz),
803 new DateTime('2011-10-03', $tz),
804 new DateTime('2011-10-30', $tz),
805 new DateTime('2016-04-04', $tz),
806 new DateTime('2016-04-24', $tz),
807 new DateTime('2016-10-03', $tz),
808 new DateTime('2016-10-30', $tz),
816 * @depends testValues
818 function testFastForward() {
820 $ev = new Sabre_VObject_Component('VEVENT');
822 $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU';
823 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
824 $dtStart->setDateTime(new DateTime('2011-04-04'),Sabre_VObject_Property_DateTime::UTC);
828 $vcal = Sabre_VObject_Component::create('VCALENDAR');
831 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
833 // The idea is that we're fast-forwarding too far in the future, so
834 // there will be no results left.
835 $it->fastForward(new DateTime('2020-05-05'));
839 while($item = $it->current()) {
849 $tz = new DateTimeZone('UTC');
850 $this->assertEquals(array(), $result);
855 * @depends testValues
857 function testComplexExclusions() {
859 $ev = new Sabre_VObject_Component('VEVENT');
861 $ev->RRULE = 'FREQ=YEARLY;COUNT=10';
862 $dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
864 $tz = new DateTimeZone('Canada/Eastern');
865 $dtStart->setDateTime(new DateTime('2011-01-01 13:50:20', $tz),Sabre_VObject_Property_DateTime::LOCALTZ);
867 $exDate1 = new Sabre_VObject_Property_MultiDateTime('EXDATE');
868 $exDate1->setDateTimes(array(new DateTime('2012-01-01 13:50:20', $tz), new DateTime('2014-01-01 13:50:20', $tz)), Sabre_VObject_Property_DateTime::LOCALTZ);
869 $exDate2 = new Sabre_VObject_Property_MultiDateTime('EXDATE');
870 $exDate2->setDateTimes(array(new DateTime('2016-01-01 13:50:20', $tz)), Sabre_VObject_Property_DateTime::LOCALTZ);
876 $vcal = Sabre_VObject_Component::create('VCALENDAR');
879 $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
881 $this->assertEquals('yearly', $it->frequency);
882 $this->assertEquals(1, $it->interval);
883 $this->assertEquals(10, $it->count);
887 foreach($it as $k=>$item) {
898 new DateTime('2011-01-01 13:50:20', $tz),
899 new DateTime('2013-01-01 13:50:20', $tz),
900 new DateTime('2015-01-01 13:50:20', $tz),
901 new DateTime('2017-01-01 13:50:20', $tz),
902 new DateTime('2018-01-01 13:50:20', $tz),
903 new DateTime('2019-01-01 13:50:20', $tz),
904 new DateTime('2020-01-01 13:50:20', $tz),
912 * @depends testValues
914 function testOverridenEvent() {
916 $vcal = Sabre_VObject_Component::create('VCALENDAR');
918 $ev1 = Sabre_VObject_Component::create('VEVENT');
919 $ev1->UID = 'overridden';
920 $ev1->RRULE = 'FREQ=DAILY;COUNT=10';
921 $ev1->DTSTART = '20120107T120000Z';
922 $ev1->SUMMARY = 'baseEvent';
926 // ev2 overrides an event, and puts it on 2pm instead.
927 $ev2 = Sabre_VObject_Component::create('VEVENT');
928 $ev2->UID = 'overridden';
929 $ev2->{'RECURRENCE-ID'} = '20120110T120000Z';
930 $ev2->DTSTART = '20120110T140000Z';
931 $ev2->SUMMARY = 'Event 2';
935 // ev3 overrides an event, and puts it 2 days and 2 hours later
936 $ev3 = Sabre_VObject_Component::create('VEVENT');
937 $ev3->UID = 'overridden';
938 $ev3->{'RECURRENCE-ID'} = '20120113T120000Z';
939 $ev3->DTSTART = '20120115T140000Z';
940 $ev3->SUMMARY = 'Event 3';
944 $it = new Sabre_VObject_RecurrenceIterator($vcal,'overridden');
947 $summaries = array();
948 while($it->valid()) {
950 $dates[] = $it->getDTStart();
951 $summaries[] = (string)$it->getEventObject()->SUMMARY;
956 $tz = new DateTimeZone('GMT');
957 $this->assertEquals(array(
958 new DateTime('2012-01-07 12:00:00',$tz),
959 new DateTime('2012-01-08 12:00:00',$tz),
960 new DateTime('2012-01-09 12:00:00',$tz),
961 new DateTime('2012-01-10 14:00:00',$tz),
962 new DateTime('2012-01-11 12:00:00',$tz),
963 new DateTime('2012-01-12 12:00:00',$tz),
964 new DateTime('2012-01-14 12:00:00',$tz),
965 new DateTime('2012-01-15 12:00:00',$tz),
966 new DateTime('2012-01-15 14:00:00',$tz),
967 new DateTime('2012-01-16 12:00:00',$tz),
970 $this->assertEquals(array(
986 * @depends testValues
988 function testOverridenEvent2() {
990 $vcal = Sabre_VObject_Component::create('VCALENDAR');
992 $ev1 = Sabre_VObject_Component::create('VEVENT');
993 $ev1->UID = 'overridden';
994 $ev1->RRULE = 'FREQ=WEEKLY;COUNT=3';
995 $ev1->DTSTART = '20120112T120000Z';
996 $ev1->SUMMARY = 'baseEvent';
1000 // ev2 overrides an event, and puts it 6 days earlier instead.
1001 $ev2 = Sabre_VObject_Component::create('VEVENT');
1002 $ev2->UID = 'overridden';
1003 $ev2->{'RECURRENCE-ID'} = '20120119T120000Z';
1004 $ev2->DTSTART = '20120113T120000Z';
1005 $ev2->SUMMARY = 'Override!';
1009 $it = new Sabre_VObject_RecurrenceIterator($vcal,'overridden');
1012 $summaries = array();
1013 while($it->valid()) {
1015 $dates[] = $it->getDTStart();
1016 $summaries[] = (string)$it->getEventObject()->SUMMARY;
1021 $tz = new DateTimeZone('GMT');
1022 $this->assertEquals(array(
1023 new DateTime('2012-01-12 12:00:00',$tz),
1024 new DateTime('2012-01-13 12:00:00',$tz),
1025 new DateTime('2012-01-26 12:00:00',$tz),
1029 $this->assertEquals(array(
1038 * @depends testValues
1040 function testOverridenEventNoValuesExpected() {
1042 $vcal = Sabre_VObject_Component::create('VCALENDAR');
1044 $ev1 = Sabre_VObject_Component::create('VEVENT');
1045 $ev1->UID = 'overridden';
1046 $ev1->RRULE = 'FREQ=WEEKLY;COUNT=3';
1047 $ev1->DTSTART = '20120124T120000Z';
1048 $ev1->SUMMARY = 'baseEvent';
1052 // ev2 overrides an event, and puts it 6 days earlier instead.
1053 $ev2 = Sabre_VObject_Component::create('VEVENT');
1054 $ev2->UID = 'overridden';
1055 $ev2->{'RECURRENCE-ID'} = '20120131T120000Z';
1056 $ev2->DTSTART = '20120125T120000Z';
1057 $ev2->SUMMARY = 'Override!';
1061 $it = new Sabre_VObject_RecurrenceIterator($vcal,'overridden');
1064 $summaries = array();
1066 // The reported problem was specifically related to the VCALENDAR
1067 // expansion. In this parcitular case, we had to forward to the 28th of
1069 $it->fastForward(new DateTime('2012-01-28 23:00:00'));
1071 // We stop the loop when it hits the 6th of februari. Normally this
1072 // iterator would hit 24, 25 (overriden from 31) and 7 feb but because
1073 // we 'filter' from the 28th till the 6th, we should get 0 results.
1074 while($it->valid() && $it->getDTSTart() < new DateTime('2012-02-06 23:00:00')) {
1076 $dates[] = $it->getDTStart();
1077 $summaries[] = (string)$it->getEventObject()->SUMMARY;
1082 $this->assertEquals(array(), $dates);
1083 $this->assertEquals(array(), $summaries);