3 namespace Sabre\VObject;
8 class RecurrenceIteratorTest extends \PHPUnit_Framework_TestCase {
10 function testValues() {
12 $ev = new Component('VEVENT');
14 $ev->RRULE = 'FREQ=DAILY;BYHOUR=10;BYMINUTE=5;BYSECOND=16;BYWEEKNO=32;BYYEARDAY=100,200';
15 $dtStart = new Property\DateTime('DTSTART');
16 $dtStart->setDateTime(new DateTime('2011-10-07'),Property\DateTime::UTC);
20 $vcal = Component::create('VCALENDAR');
23 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
25 $this->assertEquals(array(10), $it->byHour);
26 $this->assertEquals(array(5), $it->byMinute);
27 $this->assertEquals(array(16), $it->bySecond);
28 $this->assertEquals(array(32), $it->byWeekNo);
29 $this->assertEquals(array(100,200), $it->byYearDay);
34 * @expectedException InvalidArgumentException
37 function testInvalidFreq() {
39 $ev = new Component('VEVENT');
40 $ev->RRULE = 'FREQ=SMONTHLY;INTERVAL=3;UNTIL=20111025T000000Z';
41 $dtStart = new Property\DateTime('DTSTART');
42 $dtStart->setDateTime(new DateTime('2011-10-07'),Property\DateTime::UTC);
46 $vcal = Component::create('VCALENDAR');
49 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
54 * @expectedException InvalidArgumentException
56 function testVCalendarNoUID() {
58 $vcal = new Component('VCALENDAR');
59 $it = new RecurrenceIterator($vcal);
64 * @expectedException InvalidArgumentException
66 function testVCalendarInvalidUID() {
68 $vcal = new Component('VCALENDAR');
69 $it = new RecurrenceIterator($vcal,'foo');
76 function testDaily() {
78 $ev = new Component('VEVENT');
80 $ev->RRULE = 'FREQ=DAILY;INTERVAL=3;UNTIL=20111025T000000Z';
81 $dtStart = new Property\DateTime('DTSTART');
82 $dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
86 $vcal = Component::create('VCALENDAR');
89 $it = new RecurrenceIterator($vcal,$ev->uid);
91 $this->assertEquals('daily', $it->frequency);
92 $this->assertEquals(3, $it->interval);
93 $this->assertEquals(new DateTime('2011-10-25', new DateTimeZone('UTC')), $it->until);
95 // Max is to prevent overflow
98 foreach($it as $item) {
107 $tz = new DateTimeZone('UTC');
111 new DateTime('2011-10-07', $tz),
112 new DateTime('2011-10-10', $tz),
113 new DateTime('2011-10-13', $tz),
114 new DateTime('2011-10-16', $tz),
115 new DateTime('2011-10-19', $tz),
116 new DateTime('2011-10-22', $tz),
117 new DateTime('2011-10-25', $tz),
125 * @depends testValues
127 function testNoRRULE() {
129 $ev = new Component('VEVENT');
131 $dtStart = new Property\DateTime('DTSTART');
132 $dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
136 $vcal = Component::create('VCALENDAR');
139 $it = new RecurrenceIterator($vcal,$ev->uid);
141 $this->assertEquals('daily', $it->frequency);
142 $this->assertEquals(1, $it->interval);
144 // Max is to prevent overflow
147 foreach($it as $item) {
156 $tz = new DateTimeZone('UTC');
160 new DateTime('2011-10-07', $tz),
168 * @depends testValues
170 function testDailyByDay() {
172 $ev = new Component('VEVENT');
174 $ev->RRULE = 'FREQ=DAILY;INTERVAL=2;BYDAY=TU,WE,FR';
175 $dtStart = new Property\DateTime('DTSTART');
176 $dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
180 $vcal = Component::create('VCALENDAR');
183 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
185 $this->assertEquals('daily', $it->frequency);
186 $this->assertEquals(2, $it->interval);
187 $this->assertEquals(array('TU','WE','FR'), $it->byDay);
189 // Grabbing the next 12 items
192 foreach($it as $item) {
201 $tz = new DateTimeZone('UTC');
205 new DateTime('2011-10-07', $tz),
206 new DateTime('2011-10-11', $tz),
207 new DateTime('2011-10-19', $tz),
208 new DateTime('2011-10-21', $tz),
209 new DateTime('2011-10-25', $tz),
210 new DateTime('2011-11-02', $tz),
211 new DateTime('2011-11-04', $tz),
212 new DateTime('2011-11-08', $tz),
213 new DateTime('2011-11-16', $tz),
214 new DateTime('2011-11-18', $tz),
215 new DateTime('2011-11-22', $tz),
216 new DateTime('2011-11-30', $tz),
224 * @depends testValues
226 function testWeekly() {
228 $ev = new Component('VEVENT');
230 $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;COUNT=10';
231 $dtStart = new Property\DateTime('DTSTART');
232 $dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
236 $vcal = Component::create('VCALENDAR');
239 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
241 $this->assertEquals('weekly', $it->frequency);
242 $this->assertEquals(2, $it->interval);
243 $this->assertEquals(10, $it->count);
245 // Max is to prevent overflow
248 foreach($it as $item) {
257 $tz = new DateTimeZone('UTC');
261 new DateTime('2011-10-07', $tz),
262 new DateTime('2011-10-21', $tz),
263 new DateTime('2011-11-04', $tz),
264 new DateTime('2011-11-18', $tz),
265 new DateTime('2011-12-02', $tz),
266 new DateTime('2011-12-16', $tz),
267 new DateTime('2011-12-30', $tz),
268 new DateTime('2012-01-13', $tz),
269 new DateTime('2012-01-27', $tz),
270 new DateTime('2012-02-10', $tz),
278 * @depends testValues
280 function testWeeklyByDay() {
282 $ev = new Component('VEVENT');
284 $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU';
285 $dtStart = new Property\DateTime('DTSTART');
286 $dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
290 $vcal = Component::create('VCALENDAR');
293 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
295 $this->assertEquals('weekly', $it->frequency);
296 $this->assertEquals(2, $it->interval);
297 $this->assertEquals(array('TU','WE','FR'), $it->byDay);
298 $this->assertEquals('SU', $it->weekStart);
300 // Grabbing the next 12 items
303 foreach($it as $item) {
312 $tz = new DateTimeZone('UTC');
316 new DateTime('2011-10-07', $tz),
317 new DateTime('2011-10-18', $tz),
318 new DateTime('2011-10-19', $tz),
319 new DateTime('2011-10-21', $tz),
320 new DateTime('2011-11-01', $tz),
321 new DateTime('2011-11-02', $tz),
322 new DateTime('2011-11-04', $tz),
323 new DateTime('2011-11-15', $tz),
324 new DateTime('2011-11-16', $tz),
325 new DateTime('2011-11-18', $tz),
326 new DateTime('2011-11-29', $tz),
327 new DateTime('2011-11-30', $tz),
335 * @depends testValues
337 function testMonthly() {
339 $ev = new Component('VEVENT');
341 $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=3;COUNT=5';
342 $dtStart = new Property\DateTime('DTSTART');
343 $dtStart->setDateTime(new DateTime('2011-12-05', new DateTimeZone('UTC')),Property\DateTime::UTC);
347 $vcal = Component::create('VCALENDAR');
350 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
352 $this->assertEquals('monthly', $it->frequency);
353 $this->assertEquals(3, $it->interval);
354 $this->assertEquals(5, $it->count);
358 foreach($it as $item) {
367 $tz = new DateTimeZone('UTC');
371 new DateTime('2011-12-05', $tz),
372 new DateTime('2012-03-05', $tz),
373 new DateTime('2012-06-05', $tz),
374 new DateTime('2012-09-05', $tz),
375 new DateTime('2012-12-05', $tz),
384 * @depends testValues
386 function testMonthlyEndOfMonth() {
388 $ev = new Component('VEVENT');
390 $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=12';
391 $dtStart = new Property\DateTime('DTSTART');
392 $dtStart->setDateTime(new DateTime('2011-12-31', new DateTimeZone('UTC')),Property\DateTime::UTC);
396 $vcal = Component::create('VCALENDAR');
399 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
401 $this->assertEquals('monthly', $it->frequency);
402 $this->assertEquals(2, $it->interval);
403 $this->assertEquals(12, $it->count);
407 foreach($it as $item) {
416 $tz = new DateTimeZone('UTC');
420 new DateTime('2011-12-31', $tz),
421 new DateTime('2012-08-31', $tz),
422 new DateTime('2012-10-31', $tz),
423 new DateTime('2012-12-31', $tz),
424 new DateTime('2013-08-31', $tz),
425 new DateTime('2013-10-31', $tz),
426 new DateTime('2013-12-31', $tz),
427 new DateTime('2014-08-31', $tz),
428 new DateTime('2014-10-31', $tz),
429 new DateTime('2014-12-31', $tz),
430 new DateTime('2015-08-31', $tz),
431 new DateTime('2015-10-31', $tz),
440 * @depends testValues
442 function testMonthlyByMonthDay() {
444 $ev = new Component('VEVENT');
446 $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=5;COUNT=9;BYMONTHDAY=1,31,-7';
447 $dtStart = new Property\DateTime('DTSTART');
448 $dtStart->setDateTime(new DateTime('2011-01-01', new DateTimeZone('UTC')),Property\DateTime::UTC);
452 $vcal = Component::create('VCALENDAR');
455 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
457 $this->assertEquals('monthly', $it->frequency);
458 $this->assertEquals(5, $it->interval);
459 $this->assertEquals(9, $it->count);
460 $this->assertEquals(array(1, 31, -7), $it->byMonthDay);
464 foreach($it as $item) {
473 $tz = new DateTimeZone('UTC');
477 new DateTime('2011-01-01', $tz),
478 new DateTime('2011-01-25', $tz),
479 new DateTime('2011-01-31', $tz),
480 new DateTime('2011-06-01', $tz),
481 new DateTime('2011-06-24', $tz),
482 new DateTime('2011-11-01', $tz),
483 new DateTime('2011-11-24', $tz),
484 new DateTime('2012-04-01', $tz),
485 new DateTime('2012-04-24', $tz),
493 * @depends testValues
495 function testMonthlyByDay() {
497 $ev = new Component('VEVENT');
499 $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=16;BYDAY=MO,-2TU,+1WE,3TH';
500 $dtStart = new Property\DateTime('DTSTART');
501 $dtStart->setDateTime(new DateTime('2011-01-03', new DateTimeZone('UTC')),Property\DateTime::UTC);
505 $vcal = Component::create('VCALENDAR');
508 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
510 $this->assertEquals('monthly', $it->frequency);
511 $this->assertEquals(2, $it->interval);
512 $this->assertEquals(16, $it->count);
513 $this->assertEquals(array('MO','-2TU','+1WE','3TH'), $it->byDay);
517 foreach($it as $k=>$item) {
526 $tz = new DateTimeZone('UTC');
530 new DateTime('2011-01-03', $tz),
531 new DateTime('2011-01-05', $tz),
532 new DateTime('2011-01-10', $tz),
533 new DateTime('2011-01-17', $tz),
534 new DateTime('2011-01-18', $tz),
535 new DateTime('2011-01-20', $tz),
536 new DateTime('2011-01-24', $tz),
537 new DateTime('2011-01-31', $tz),
538 new DateTime('2011-03-02', $tz),
539 new DateTime('2011-03-07', $tz),
540 new DateTime('2011-03-14', $tz),
541 new DateTime('2011-03-17', $tz),
542 new DateTime('2011-03-21', $tz),
543 new DateTime('2011-03-22', $tz),
544 new DateTime('2011-03-28', $tz),
545 new DateTime('2011-05-02', $tz),
553 * @depends testValues
555 function testMonthlyByDayByMonthDay() {
557 $ev = new Component('VEVENT');
559 $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO;BYMONTHDAY=1';
560 $dtStart = new Property\DateTime('DTSTART');
561 $dtStart->setDateTime(new DateTime('2011-08-01', new DateTimeZone('UTC')),Property\DateTime::UTC);
565 $vcal = Component::create('VCALENDAR');
568 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
570 $this->assertEquals('monthly', $it->frequency);
571 $this->assertEquals(1, $it->interval);
572 $this->assertEquals(10, $it->count);
573 $this->assertEquals(array('MO'), $it->byDay);
574 $this->assertEquals(array(1), $it->byMonthDay);
578 foreach($it as $k=>$item) {
587 $tz = new DateTimeZone('UTC');
591 new DateTime('2011-08-01', $tz),
592 new DateTime('2012-10-01', $tz),
593 new DateTime('2013-04-01', $tz),
594 new DateTime('2013-07-01', $tz),
595 new DateTime('2014-09-01', $tz),
596 new DateTime('2014-12-01', $tz),
597 new DateTime('2015-06-01', $tz),
598 new DateTime('2016-02-01', $tz),
599 new DateTime('2016-08-01', $tz),
600 new DateTime('2017-05-01', $tz),
608 * @depends testValues
610 function testMonthlyByDayBySetPos() {
612 $ev = new Component('VEVENT');
614 $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1';
615 $dtStart = new Property\DateTime('DTSTART');
616 $dtStart->setDateTime(new DateTime('2011-01-03', new DateTimeZone('UTC')),Property\DateTime::UTC);
620 $vcal = Component::create('VCALENDAR');
623 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
625 $this->assertEquals('monthly', $it->frequency);
626 $this->assertEquals(1, $it->interval);
627 $this->assertEquals(10, $it->count);
628 $this->assertEquals(array('MO','TU','WE','TH','FR'), $it->byDay);
629 $this->assertEquals(array(1,-1), $it->bySetPos);
633 foreach($it as $k=>$item) {
642 $tz = new DateTimeZone('UTC');
646 new DateTime('2011-01-03', $tz),
647 new DateTime('2011-01-31', $tz),
648 new DateTime('2011-02-01', $tz),
649 new DateTime('2011-02-28', $tz),
650 new DateTime('2011-03-01', $tz),
651 new DateTime('2011-03-31', $tz),
652 new DateTime('2011-04-01', $tz),
653 new DateTime('2011-04-29', $tz),
654 new DateTime('2011-05-02', $tz),
655 new DateTime('2011-05-31', $tz),
663 * @depends testValues
665 function testYearly() {
667 $ev = new Component('VEVENT');
669 $ev->RRULE = 'FREQ=YEARLY;COUNT=10;INTERVAL=3';
670 $dtStart = new Property\DateTime('DTSTART');
671 $dtStart->setDateTime(new DateTime('2011-01-01', new DateTimeZone('UTC')),Property\DateTime::UTC);
675 $vcal = Component::create('VCALENDAR');
678 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
680 $this->assertEquals('yearly', $it->frequency);
681 $this->assertEquals(3, $it->interval);
682 $this->assertEquals(10, $it->count);
686 foreach($it as $k=>$item) {
695 $tz = new DateTimeZone('UTC');
699 new DateTime('2011-01-01', $tz),
700 new DateTime('2014-01-01', $tz),
701 new DateTime('2017-01-01', $tz),
702 new DateTime('2020-01-01', $tz),
703 new DateTime('2023-01-01', $tz),
704 new DateTime('2026-01-01', $tz),
705 new DateTime('2029-01-01', $tz),
706 new DateTime('2032-01-01', $tz),
707 new DateTime('2035-01-01', $tz),
708 new DateTime('2038-01-01', $tz),
716 * @depends testValues
718 function testYearlyLeapYear() {
720 $ev = new Component('VEVENT');
722 $ev->RRULE = 'FREQ=YEARLY;COUNT=3';
723 $dtStart = new Property\DateTime('DTSTART');
724 $dtStart->setDateTime(new DateTime('2012-02-29', new DateTimeZone('UTC')),Property\DateTime::UTC);
728 $vcal = Component::create('VCALENDAR');
731 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
733 $this->assertEquals('yearly', $it->frequency);
734 $this->assertEquals(3, $it->count);
738 foreach($it as $k=>$item) {
747 $tz = new DateTimeZone('UTC');
751 new DateTime('2012-02-29', $tz),
752 new DateTime('2016-02-29', $tz),
753 new DateTime('2020-02-29', $tz),
761 * @depends testValues
763 function testYearlyByMonth() {
765 $ev = new Component('VEVENT');
767 $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYMONTH=4,10';
768 $dtStart = new Property\DateTime('DTSTART');
769 $dtStart->setDateTime(new DateTime('2011-04-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
773 $vcal = Component::create('VCALENDAR');
776 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
778 $this->assertEquals('yearly', $it->frequency);
779 $this->assertEquals(4, $it->interval);
780 $this->assertEquals(8, $it->count);
781 $this->assertEquals(array(4,10), $it->byMonth);
785 foreach($it as $k=>$item) {
794 $tz = new DateTimeZone('UTC');
798 new DateTime('2011-04-07', $tz),
799 new DateTime('2011-10-07', $tz),
800 new DateTime('2015-04-07', $tz),
801 new DateTime('2015-10-07', $tz),
802 new DateTime('2019-04-07', $tz),
803 new DateTime('2019-10-07', $tz),
804 new DateTime('2023-04-07', $tz),
805 new DateTime('2023-10-07', $tz),
813 * @depends testValues
815 function testYearlyByMonthByDay() {
817 $ev = new Component('VEVENT');
819 $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU';
820 $dtStart = new Property\DateTime('DTSTART');
821 $dtStart->setDateTime(new DateTime('2011-04-04', new DateTimeZone('UTC')),Property\DateTime::UTC);
825 $vcal = Component::create('VCALENDAR');
828 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
830 $this->assertEquals('yearly', $it->frequency);
831 $this->assertEquals(5, $it->interval);
832 $this->assertEquals(8, $it->count);
833 $this->assertEquals(array(4,10), $it->byMonth);
834 $this->assertEquals(array('1MO','-1SU'), $it->byDay);
838 foreach($it as $k=>$item) {
847 $tz = new DateTimeZone('UTC');
851 new DateTime('2011-04-04', $tz),
852 new DateTime('2011-04-24', $tz),
853 new DateTime('2011-10-03', $tz),
854 new DateTime('2011-10-30', $tz),
855 new DateTime('2016-04-04', $tz),
856 new DateTime('2016-04-24', $tz),
857 new DateTime('2016-10-03', $tz),
858 new DateTime('2016-10-30', $tz),
866 * @depends testValues
868 function testFastForward() {
870 $ev = new Component('VEVENT');
872 $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU';
873 $dtStart = new Property\DateTime('DTSTART');
874 $dtStart->setDateTime(new DateTime('2011-04-04', new DateTimeZone('UTC')),Property\DateTime::UTC);
878 $vcal = Component::create('VCALENDAR');
881 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
883 // The idea is that we're fast-forwarding too far in the future, so
884 // there will be no results left.
885 $it->fastForward(new DateTime('2020-05-05', new DateTimeZone('UTC')));
889 while($item = $it->current()) {
899 $tz = new DateTimeZone('UTC');
900 $this->assertEquals(array(), $result);
905 * @depends testValues
907 function testComplexExclusions() {
909 $ev = new Component('VEVENT');
911 $ev->RRULE = 'FREQ=YEARLY;COUNT=10';
912 $dtStart = new Property\DateTime('DTSTART');
914 $tz = new DateTimeZone('Canada/Eastern');
915 $dtStart->setDateTime(new DateTime('2011-01-01 13:50:20', $tz),Property\DateTime::LOCALTZ);
917 $exDate1 = new Property\MultiDateTime('EXDATE');
918 $exDate1->setDateTimes(array(new DateTime('2012-01-01 13:50:20', $tz), new DateTime('2014-01-01 13:50:20', $tz)), Property\DateTime::LOCALTZ);
919 $exDate2 = new Property\MultiDateTime('EXDATE');
920 $exDate2->setDateTimes(array(new DateTime('2016-01-01 13:50:20', $tz)), Property\DateTime::LOCALTZ);
926 $vcal = Component::create('VCALENDAR');
929 $it = new RecurrenceIterator($vcal,(string)$ev->uid);
931 $this->assertEquals('yearly', $it->frequency);
932 $this->assertEquals(1, $it->interval);
933 $this->assertEquals(10, $it->count);
937 foreach($it as $k=>$item) {
948 new DateTime('2011-01-01 13:50:20', $tz),
949 new DateTime('2013-01-01 13:50:20', $tz),
950 new DateTime('2015-01-01 13:50:20', $tz),
951 new DateTime('2017-01-01 13:50:20', $tz),
952 new DateTime('2018-01-01 13:50:20', $tz),
953 new DateTime('2019-01-01 13:50:20', $tz),
954 new DateTime('2020-01-01 13:50:20', $tz),
962 * @depends testValues
964 function testOverridenEvent() {
966 $vcal = Component::create('VCALENDAR');
968 $ev1 = Component::create('VEVENT');
969 $ev1->UID = 'overridden';
970 $ev1->RRULE = 'FREQ=DAILY;COUNT=10';
971 $ev1->DTSTART = '20120107T120000Z';
972 $ev1->SUMMARY = 'baseEvent';
976 // ev2 overrides an event, and puts it on 2pm instead.
977 $ev2 = Component::create('VEVENT');
978 $ev2->UID = 'overridden';
979 $ev2->{'RECURRENCE-ID'} = '20120110T120000Z';
980 $ev2->DTSTART = '20120110T140000Z';
981 $ev2->SUMMARY = 'Event 2';
985 // ev3 overrides an event, and puts it 2 days and 2 hours later
986 $ev3 = Component::create('VEVENT');
987 $ev3->UID = 'overridden';
988 $ev3->{'RECURRENCE-ID'} = '20120113T120000Z';
989 $ev3->DTSTART = '20120115T140000Z';
990 $ev3->SUMMARY = 'Event 3';
994 $it = new RecurrenceIterator($vcal,'overridden');
997 $summaries = array();
998 while($it->valid()) {
1000 $dates[] = $it->getDTStart();
1001 $summaries[] = (string)$it->getEventObject()->SUMMARY;
1006 $tz = new DateTimeZone('GMT');
1007 $this->assertEquals(array(
1008 new DateTime('2012-01-07 12:00:00',$tz),
1009 new DateTime('2012-01-08 12:00:00',$tz),
1010 new DateTime('2012-01-09 12:00:00',$tz),
1011 new DateTime('2012-01-10 14:00:00',$tz),
1012 new DateTime('2012-01-11 12:00:00',$tz),
1013 new DateTime('2012-01-12 12:00:00',$tz),
1014 new DateTime('2012-01-14 12:00:00',$tz),
1015 new DateTime('2012-01-15 12:00:00',$tz),
1016 new DateTime('2012-01-15 14:00:00',$tz),
1017 new DateTime('2012-01-16 12:00:00',$tz),
1020 $this->assertEquals(array(
1036 * @depends testValues
1038 function testOverridenEvent2() {
1040 $vcal = Component::create('VCALENDAR');
1042 $ev1 = Component::create('VEVENT');
1043 $ev1->UID = 'overridden';
1044 $ev1->RRULE = 'FREQ=WEEKLY;COUNT=3';
1045 $ev1->DTSTART = '20120112T120000Z';
1046 $ev1->SUMMARY = 'baseEvent';
1050 // ev2 overrides an event, and puts it 6 days earlier instead.
1051 $ev2 = Component::create('VEVENT');
1052 $ev2->UID = 'overridden';
1053 $ev2->{'RECURRENCE-ID'} = '20120119T120000Z';
1054 $ev2->DTSTART = '20120113T120000Z';
1055 $ev2->SUMMARY = 'Override!';
1059 $it = new RecurrenceIterator($vcal,'overridden');
1062 $summaries = array();
1063 while($it->valid()) {
1065 $dates[] = $it->getDTStart();
1066 $summaries[] = (string)$it->getEventObject()->SUMMARY;
1071 $tz = new DateTimeZone('GMT');
1072 $this->assertEquals(array(
1073 new DateTime('2012-01-12 12:00:00',$tz),
1074 new DateTime('2012-01-13 12:00:00',$tz),
1075 new DateTime('2012-01-26 12:00:00',$tz),
1079 $this->assertEquals(array(
1088 * @depends testValues
1090 function testOverridenEventNoValuesExpected() {
1092 $vcal = Component::create('VCALENDAR');
1094 $ev1 = Component::create('VEVENT');
1095 $ev1->UID = 'overridden';
1096 $ev1->RRULE = 'FREQ=WEEKLY;COUNT=3';
1097 $ev1->DTSTART = '20120124T120000Z';
1098 $ev1->SUMMARY = 'baseEvent';
1102 // ev2 overrides an event, and puts it 6 days earlier instead.
1103 $ev2 = Component::create('VEVENT');
1104 $ev2->UID = 'overridden';
1105 $ev2->{'RECURRENCE-ID'} = '20120131T120000Z';
1106 $ev2->DTSTART = '20120125T120000Z';
1107 $ev2->SUMMARY = 'Override!';
1111 $it = new RecurrenceIterator($vcal,'overridden');
1114 $summaries = array();
1116 // The reported problem was specifically related to the VCALENDAR
1117 // expansion. In this parcitular case, we had to forward to the 28th of
1119 $it->fastForward(new DateTime('2012-01-28 23:00:00'));
1121 // We stop the loop when it hits the 6th of februari. Normally this
1122 // iterator would hit 24, 25 (overriden from 31) and 7 feb but because
1123 // we 'filter' from the 28th till the 6th, we should get 0 results.
1124 while($it->valid() && $it->getDTSTart() < new DateTime('2012-02-06 23:00:00')) {
1126 $dates[] = $it->getDTStart();
1127 $summaries[] = (string)$it->getEventObject()->SUMMARY;
1132 $this->assertEquals(array(), $dates);
1133 $this->assertEquals(array(), $summaries);