ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
RRuleIteratorTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\VObject\Recur;
4
5use DateTime;
6use DateTimeImmutable;
7use DateTimeZone;
8use PHPUnit\Framework\TestCase;
9
10class RRuleIteratorTest extends TestCase {
11
12 function testHourly() {
13
14 $this->parse(
15 'FREQ=HOURLY;INTERVAL=3;COUNT=12',
16 '2011-10-07 12:00:00',
17 [
18 '2011-10-07 12:00:00',
19 '2011-10-07 15:00:00',
20 '2011-10-07 18:00:00',
21 '2011-10-07 21:00:00',
22 '2011-10-08 00:00:00',
23 '2011-10-08 03:00:00',
24 '2011-10-08 06:00:00',
25 '2011-10-08 09:00:00',
26 '2011-10-08 12:00:00',
27 '2011-10-08 15:00:00',
28 '2011-10-08 18:00:00',
29 '2011-10-08 21:00:00',
30 ]
31 );
32
33 }
34
35 function testDaily() {
36
37 $this->parse(
38 'FREQ=DAILY;INTERVAL=3;UNTIL=20111025T000000Z',
39 '2011-10-07',
40 [
41 '2011-10-07 00:00:00',
42 '2011-10-10 00:00:00',
43 '2011-10-13 00:00:00',
44 '2011-10-16 00:00:00',
45 '2011-10-19 00:00:00',
46 '2011-10-22 00:00:00',
47 '2011-10-25 00:00:00',
48 ]
49 );
50
51 }
52
54
55 $this->parse(
56 'FREQ=DAILY;BYDAY=SA,SU;BYHOUR=6,7',
57 '2011-10-08 06:00:00',
58 [
59 '2011-10-08 06:00:00',
60 '2011-10-08 07:00:00',
61 '2011-10-09 06:00:00',
62 '2011-10-09 07:00:00',
63 '2011-10-15 06:00:00',
64 '2011-10-15 07:00:00',
65 '2011-10-16 06:00:00',
66 '2011-10-16 07:00:00',
67 '2011-10-22 06:00:00',
68 '2011-10-22 07:00:00',
69 '2011-10-23 06:00:00',
70 '2011-10-23 07:00:00',
71 ]
72 );
73
74 }
75
76 function testDailyByHour() {
77
78 $this->parse(
79 'FREQ=DAILY;INTERVAL=2;BYHOUR=10,11,12,13,14,15',
80 '2012-10-11 12:00:00',
81 [
82 '2012-10-11 12:00:00',
83 '2012-10-11 13:00:00',
84 '2012-10-11 14:00:00',
85 '2012-10-11 15:00:00',
86 '2012-10-13 10:00:00',
87 '2012-10-13 11:00:00',
88 '2012-10-13 12:00:00',
89 '2012-10-13 13:00:00',
90 '2012-10-13 14:00:00',
91 '2012-10-13 15:00:00',
92 '2012-10-15 10:00:00',
93 '2012-10-15 11:00:00',
94 ]
95 );
96
97 }
98
99 function testDailyByDay() {
100
101 $this->parse(
102 'FREQ=DAILY;INTERVAL=2;BYDAY=TU,WE,FR',
103 '2011-10-07 12:00:00',
104 [
105 '2011-10-07 12:00:00',
106 '2011-10-11 12:00:00',
107 '2011-10-19 12:00:00',
108 '2011-10-21 12:00:00',
109 '2011-10-25 12:00:00',
110 '2011-11-02 12:00:00',
111 '2011-11-04 12:00:00',
112 '2011-11-08 12:00:00',
113 '2011-11-16 12:00:00',
114 '2011-11-18 12:00:00',
115 '2011-11-22 12:00:00',
116 '2011-11-30 12:00:00',
117 ]
118 );
119
120 }
121
122 function testDailyCount() {
123
124 $this->parse(
125 'FREQ=DAILY;COUNT=5',
126 '2014-08-01 18:03:00',
127 [
128 '2014-08-01 18:03:00',
129 '2014-08-02 18:03:00',
130 '2014-08-03 18:03:00',
131 '2014-08-04 18:03:00',
132 '2014-08-05 18:03:00',
133 ]
134 );
135
136 }
137
138 function testDailyByMonth() {
139
140 $this->parse(
141 'FREQ=DAILY;BYMONTH=9,10;BYDAY=SU',
142 '2007-10-04 16:00:00',
143 [
144 '2013-09-29 16:00:00',
145 '2013-10-06 16:00:00',
146 '2013-10-13 16:00:00',
147 '2013-10-20 16:00:00',
148 '2013-10-27 16:00:00',
149 '2014-09-07 16:00:00'
150 ],
151 '2013-09-28'
152 );
153
154 }
155
156 function testWeekly() {
157
158 $this->parse(
159 'FREQ=WEEKLY;INTERVAL=2;COUNT=10',
160 '2011-10-07 00:00:00',
161 [
162 '2011-10-07 00:00:00',
163 '2011-10-21 00:00:00',
164 '2011-11-04 00:00:00',
165 '2011-11-18 00:00:00',
166 '2011-12-02 00:00:00',
167 '2011-12-16 00:00:00',
168 '2011-12-30 00:00:00',
169 '2012-01-13 00:00:00',
170 '2012-01-27 00:00:00',
171 '2012-02-10 00:00:00',
172 ]
173 );
174
175 }
176
177 function testWeeklyByDay() {
178
179 $this->parse(
180 'FREQ=WEEKLY;INTERVAL=1;COUNT=4;BYDAY=MO;WKST=SA',
181 '2014-08-01 00:00:00',
182 [
183 '2014-08-01 00:00:00',
184 '2014-08-04 00:00:00',
185 '2014-08-11 00:00:00',
186 '2014-08-18 00:00:00',
187 ]
188 );
189
190 }
191
192 function testWeeklyByDay2() {
193
194 $this->parse(
195 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU',
196 '2011-10-07 00:00:00',
197 [
198 '2011-10-07 00:00:00',
199 '2011-10-18 00:00:00',
200 '2011-10-19 00:00:00',
201 '2011-10-21 00:00:00',
202 '2011-11-01 00:00:00',
203 '2011-11-02 00:00:00',
204 '2011-11-04 00:00:00',
205 '2011-11-15 00:00:00',
206 '2011-11-16 00:00:00',
207 '2011-11-18 00:00:00',
208 '2011-11-29 00:00:00',
209 '2011-11-30 00:00:00',
210 ]
211 );
212
213 }
214
216
217 $this->parse(
218 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=MO;BYHOUR=8,9,10',
219 '2011-10-07 08:00:00',
220 [
221 '2011-10-07 08:00:00',
222 '2011-10-07 09:00:00',
223 '2011-10-07 10:00:00',
224 '2011-10-18 08:00:00',
225 '2011-10-18 09:00:00',
226 '2011-10-18 10:00:00',
227 '2011-10-19 08:00:00',
228 '2011-10-19 09:00:00',
229 '2011-10-19 10:00:00',
230 '2011-10-21 08:00:00',
231 '2011-10-21 09:00:00',
232 '2011-10-21 10:00:00',
233 '2011-11-01 08:00:00',
234 '2011-11-01 09:00:00',
235 '2011-11-01 10:00:00',
236 ]
237 );
238
239 }
240
242
243 $this->parse(
244 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU',
245 '2011-10-07 18:00:00',
246 [
247 '2011-10-07 18:00:00',
248 '2011-10-18 18:00:00',
249 '2011-10-19 18:00:00',
250 '2011-10-21 18:00:00',
251 '2011-11-01 18:00:00',
252 '2011-11-02 18:00:00',
253 '2011-11-04 18:00:00',
254 '2011-11-15 18:00:00',
255 '2011-11-16 18:00:00',
256 '2011-11-18 18:00:00',
257 '2011-11-29 18:00:00',
258 '2011-11-30 18:00:00',
259 ]
260 );
261
262 }
263
264 function testMonthly() {
265
266 $this->parse(
267 'FREQ=MONTHLY;INTERVAL=3;COUNT=5',
268 '2011-12-05 00:00:00',
269 [
270 '2011-12-05 00:00:00',
271 '2012-03-05 00:00:00',
272 '2012-06-05 00:00:00',
273 '2012-09-05 00:00:00',
274 '2012-12-05 00:00:00',
275 ]
276 );
277
278 }
279
281
282 $this->parse(
283 'FREQ=MONTHLY;INTERVAL=2;COUNT=12',
284 '2011-12-31 00:00:00',
285 [
286 '2011-12-31 00:00:00',
287 '2012-08-31 00:00:00',
288 '2012-10-31 00:00:00',
289 '2012-12-31 00:00:00',
290 '2013-08-31 00:00:00',
291 '2013-10-31 00:00:00',
292 '2013-12-31 00:00:00',
293 '2014-08-31 00:00:00',
294 '2014-10-31 00:00:00',
295 '2014-12-31 00:00:00',
296 '2015-08-31 00:00:00',
297 '2015-10-31 00:00:00',
298 ]
299 );
300
301 }
302
304
305 $this->parse(
306 'FREQ=MONTHLY;INTERVAL=5;COUNT=9;BYMONTHDAY=1,31,-7',
307 '2011-01-01 00:00:00',
308 [
309 '2011-01-01 00:00:00',
310 '2011-01-25 00:00:00',
311 '2011-01-31 00:00:00',
312 '2011-06-01 00:00:00',
313 '2011-06-24 00:00:00',
314 '2011-11-01 00:00:00',
315 '2011-11-24 00:00:00',
316 '2012-04-01 00:00:00',
317 '2012-04-24 00:00:00',
318 ]
319 );
320
321 }
322
323 function testMonthlyByDay() {
324
325 $this->parse(
326 'FREQ=MONTHLY;INTERVAL=2;COUNT=16;BYDAY=MO,-2TU,+1WE,3TH',
327 '2011-01-03 00:00:00',
328 [
329 '2011-01-03 00:00:00',
330 '2011-01-05 00:00:00',
331 '2011-01-10 00:00:00',
332 '2011-01-17 00:00:00',
333 '2011-01-18 00:00:00',
334 '2011-01-20 00:00:00',
335 '2011-01-24 00:00:00',
336 '2011-01-31 00:00:00',
337 '2011-03-02 00:00:00',
338 '2011-03-07 00:00:00',
339 '2011-03-14 00:00:00',
340 '2011-03-17 00:00:00',
341 '2011-03-21 00:00:00',
342 '2011-03-22 00:00:00',
343 '2011-03-28 00:00:00',
344 '2011-05-02 00:00:00',
345 ]
346 );
347
348 }
349
351
352 $this->parse(
353 'FREQ=MONTHLY;COUNT=10;BYDAY=MO;BYMONTHDAY=1',
354 '2011-08-01 00:00:00',
355 [
356 '2011-08-01 00:00:00',
357 '2012-10-01 00:00:00',
358 '2013-04-01 00:00:00',
359 '2013-07-01 00:00:00',
360 '2014-09-01 00:00:00',
361 '2014-12-01 00:00:00',
362 '2015-06-01 00:00:00',
363 '2016-02-01 00:00:00',
364 '2016-08-01 00:00:00',
365 '2017-05-01 00:00:00',
366 ]
367 );
368
369 }
370
372
373 $this->parse(
374 'FREQ=MONTHLY;COUNT=10;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1',
375 '2011-01-03 00:00:00',
376 [
377 '2011-01-03 00:00:00',
378 '2011-01-31 00:00:00',
379 '2011-02-01 00:00:00',
380 '2011-02-28 00:00:00',
381 '2011-03-01 00:00:00',
382 '2011-03-31 00:00:00',
383 '2011-04-01 00:00:00',
384 '2011-04-29 00:00:00',
385 '2011-05-02 00:00:00',
386 '2011-05-31 00:00:00',
387 ]
388 );
389
390 }
391
392 function testYearly() {
393
394 $this->parse(
395 'FREQ=YEARLY;COUNT=10;INTERVAL=3',
396 '2011-01-01 00:00:00',
397 [
398 '2011-01-01 00:00:00',
399 '2014-01-01 00:00:00',
400 '2017-01-01 00:00:00',
401 '2020-01-01 00:00:00',
402 '2023-01-01 00:00:00',
403 '2026-01-01 00:00:00',
404 '2029-01-01 00:00:00',
405 '2032-01-01 00:00:00',
406 '2035-01-01 00:00:00',
407 '2038-01-01 00:00:00',
408 ]
409 );
410 }
411
413
414 $this->parse(
415 'FREQ=YEARLY;COUNT=3',
416 '2012-02-29 00:00:00',
417 [
418 '2012-02-29 00:00:00',
419 '2016-02-29 00:00:00',
420 '2020-02-29 00:00:00',
421 ]
422 );
423 }
424
425 function testYearlyByMonth() {
426
427 $this->parse(
428 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYMONTH=4,10',
429 '2011-04-07 00:00:00',
430 [
431 '2011-04-07 00:00:00',
432 '2011-10-07 00:00:00',
433 '2015-04-07 00:00:00',
434 '2015-10-07 00:00:00',
435 '2019-04-07 00:00:00',
436 '2019-10-07 00:00:00',
437 '2023-04-07 00:00:00',
438 '2023-10-07 00:00:00',
439 ]
440 );
441
442 }
443
448
449 $this->parse(
450 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=0',
451 '2011-04-07 00:00:00',
452 []
453 );
454
455 }
456
461
462 $this->parse(
463 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=bla',
464 '2011-04-07 00:00:00',
465 []
466 );
467
468 }
469
474
475 $this->parse(
476 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=0,bla',
477 '2011-04-07 00:00:00',
478 []
479 );
480
481 }
482
487
488 $this->parse(
489 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=',
490 '2011-04-07 00:00:00',
491 []
492 );
493
494 }
495
497
498 $this->parse(
499 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU',
500 '2011-04-04 00:00:00',
501 [
502 '2011-04-04 00:00:00',
503 '2011-04-24 00:00:00',
504 '2011-10-03 00:00:00',
505 '2011-10-30 00:00:00',
506 '2016-04-04 00:00:00',
507 '2016-04-24 00:00:00',
508 '2016-10-03 00:00:00',
509 '2016-10-30 00:00:00',
510 ]
511 );
512
513 }
514
516
517 $this->parse(
518 'FREQ=YEARLY;COUNT=7;INTERVAL=2;BYYEARDAY=190',
519 '2011-07-10 03:07:00',
520 [
521 '2011-07-10 03:07:00',
522 '2013-07-10 03:07:00',
523 '2015-07-10 03:07:00',
524 '2017-07-10 03:07:00',
525 '2019-07-10 03:07:00',
526 '2021-07-10 03:07:00',
527 '2023-07-10 03:07:00',
528 ]
529 );
530
531 }
532
533 /*
534 * Regression test for #383
535 * $parser->next() used to cause an infinite loop.
536 */
538 $start = '2011-07-10 03:07:00';
539 $rule = 'FREQ=YEARLY;COUNT=7;INTERVAL=2;BYYEARDAY=190';
540 $tz = "UTC";
541
542 $dt = new DateTimeImmutable($start, new DateTimeZone($tz));
543 $parser = new RRuleIterator($rule, $dt);
544
545 $parser->next();
546
547 $item = $parser->current();
548 $this->assertEquals($item->format('Y-m-d H:i:s'), '2013-07-10 03:07:00');
549 }
550
552
553 $this->parse(
554 'FREQ=YEARLY;COUNT=8;INTERVAL=3;BYYEARDAY=190,301',
555 '2011-07-10 14:53:11',
556 [
557 '2011-07-10 14:53:11',
558 '2011-10-29 14:53:11',
559 '2014-07-10 14:53:11',
560 '2014-10-29 14:53:11',
561 '2017-07-10 14:53:11',
562 '2017-10-29 14:53:11',
563 '2020-07-09 14:53:11',
564 '2020-10-28 14:53:11',
565 ]
566 );
567
568 }
569
571
572 $this->parse(
573 'FREQ=YEARLY;COUNT=6;BYYEARDAY=97;BYDAY=SA',
574 '2001-04-07 14:53:11',
575 [
576 '2001-04-07 14:53:11',
577 '2006-04-08 14:53:11',
578 '2012-04-07 14:53:11',
579 '2017-04-08 14:53:11',
580 '2023-04-08 14:53:11',
581 '2034-04-08 14:53:11',
582 ]
583 );
584
585 }
586
588
589 $this->parse(
590 'FREQ=YEARLY;COUNT=8;BYYEARDAY=-97,-5',
591 '2001-09-26 14:53:11',
592 [
593 '2001-09-26 14:53:11',
594 '2001-12-27 14:53:11',
595 '2002-09-26 14:53:11',
596 '2002-12-27 14:53:11',
597 '2003-09-26 14:53:11',
598 '2003-12-27 14:53:11',
599 '2004-09-26 14:53:11',
600 '2004-12-27 14:53:11',
601 ]
602 );
603
604 }
605
610
611 $this->parse(
612 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYYEARDAY=390',
613 '2011-04-07 00:00:00',
614 [
615 ]
616 );
617
618 }
619
624
625 $this->parse(
626 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYYEARDAY=0',
627 '2011-04-07 00:00:00',
628 [
629 ]
630 );
631
632 }
633
634 function testFastForward() {
635
636 // The idea is that we're fast-forwarding too far in the future, so
637 // there will be no results left.
638 $this->parse(
639 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU',
640 '2011-04-04 00:00:00',
641 [],
642 '2020-05-05 00:00:00'
643 );
644
645 }
646
658
659 $this->parse(
660 'FREQ=MONTHLY;INTERVAL=1;UNTIL=20071030T035959Z;BYDAY=5TU',
661 '2007-10-04 14:46:42',
662 [
663 '2007-10-04 14:46:42',
664 ]
665 );
666
667 }
668
674
675 $this->parse(
676 'FREQ=WEEKLY;BYDAY=MO;UNTIL=20090704T205959Z;INTERVAL=1',
677 '2009-04-20 18:00:00',
678 [
679 '2009-04-20 18:00:00',
680 '2009-04-27 18:00:00',
681 '2009-05-04 18:00:00',
682 '2009-05-11 18:00:00',
683 '2009-05-18 18:00:00',
684 '2009-05-25 18:00:00',
685 '2009-06-01 18:00:00',
686 '2009-06-08 18:00:00',
687 '2009-06-15 18:00:00',
688 '2009-06-22 18:00:00',
689 '2009-06-29 18:00:00',
690 ]
691 );
692
693 }
694
695 function testValidByWeekNo() {
696
697 $this->parse(
698 'FREQ=YEARLY;BYWEEKNO=20;BYDAY=TU',
699 '2011-02-07 00:00:00',
700 [
701 '2011-02-07 00:00:00',
702 '2011-05-17 00:00:00',
703 '2012-05-15 00:00:00',
704 '2013-05-14 00:00:00',
705 '2014-05-13 00:00:00',
706 '2015-05-12 00:00:00',
707 '2016-05-17 00:00:00',
708 '2017-05-16 00:00:00',
709 '2018-05-15 00:00:00',
710 '2019-05-14 00:00:00',
711 '2020-05-12 00:00:00',
712 '2021-05-18 00:00:00',
713 ]
714 );
715
716 }
717
719
720 $this->parse(
721 'FREQ=YEARLY;BYWEEKNO=-20;BYDAY=TU,FR',
722 '2011-09-02 00:00:00',
723 [
724 '2011-09-02 00:00:00',
725 '2012-08-07 00:00:00',
726 '2012-08-10 00:00:00',
727 '2013-08-06 00:00:00',
728 '2013-08-09 00:00:00',
729 '2014-08-05 00:00:00',
730 '2014-08-08 00:00:00',
731 '2015-08-11 00:00:00',
732 '2015-08-14 00:00:00',
733 '2016-08-09 00:00:00',
734 '2016-08-12 00:00:00',
735 '2017-08-08 00:00:00',
736 ]
737 );
738
739 }
740
742
743 $this->parse(
744 'FREQ=YEARLY;BYWEEKNO=20;BYDAY=TU,FR',
745 '2011-09-07 09:00:00',
746 [
747 '2011-09-07 09:00:00',
748 '2012-05-15 09:00:00',
749 '2012-05-18 09:00:00',
750 '2013-05-14 09:00:00',
751 '2013-05-17 09:00:00',
752 '2014-05-13 09:00:00',
753 '2014-05-16 09:00:00',
754 '2015-05-12 09:00:00',
755 '2015-05-15 09:00:00',
756 '2016-05-17 09:00:00',
757 '2016-05-20 09:00:00',
758 '2017-05-16 09:00:00',
759 ]
760 );
761
762 }
763
765
766 $this->parse(
767 'FREQ=YEARLY;BYWEEKNO=20',
768 '2011-05-16 00:00:00',
769 [
770 '2011-05-16 00:00:00',
771 '2012-05-14 00:00:00',
772 '2013-05-13 00:00:00',
773 '2014-05-12 00:00:00',
774 '2015-05-11 00:00:00',
775 '2016-05-16 00:00:00',
776 '2017-05-15 00:00:00',
777 '2018-05-14 00:00:00',
778 '2019-05-13 00:00:00',
779 '2020-05-11 00:00:00',
780 '2021-05-17 00:00:00',
781 '2022-05-16 00:00:00',
782 ]
783 );
784
785 }
786
788
789 $this->parse(
790 'FREQ=YEARLY;BYWEEKNO=20,50;BYDAY=TU,FR',
791 '2011-01-16 00:00:00',
792 [
793 '2011-01-16 00:00:00',
794 '2011-05-17 00:00:00',
795 '2011-05-20 00:00:00',
796 '2011-12-13 00:00:00',
797 '2011-12-16 00:00:00',
798 '2012-05-15 00:00:00',
799 '2012-05-18 00:00:00',
800 '2012-12-11 00:00:00',
801 '2012-12-14 00:00:00',
802 '2013-05-14 00:00:00',
803 '2013-05-17 00:00:00',
804 '2013-12-10 00:00:00',
805 ]
806 );
807
808 }
809
814
815 $this->parse(
816 'FREQ=YEARLY;BYWEEKNO=54',
817 '2011-05-16 00:00:00',
818 [
819 ]
820 );
821
822 }
823
828
829 $this->parse(
830 'FREQ=YEARLY;INTERVAL=1;UNTIL=20120203T225959Z;BYMONTH=2;BYSETPOS=1;BYDAY=SU,MO,TU,WE,TH,FR,SA',
831 '2012-01-01 15:45:00',
832 [
833 '2012-02-01 15:45:00',
834 ],
835 '2012-01-29 23:00:00'
836 );
837
838
839 }
840
848 function testZeroInterval() {
849
850 $this->parse(
851 'FREQ=YEARLY;INTERVAL=0',
852 '2012-08-24 14:57:00',
853 [],
854 '2013-01-01 23:00:00'
855 );
856
857 }
858
862 function testInvalidFreq() {
863
864 $this->parse(
865 'FREQ=SMONTHLY;INTERVAL=3;UNTIL=20111025T000000Z',
866 '2011-10-07',
867 []
868 );
869
870 }
871
876
877 $this->parse(
878 'FREQ=WEEKLY;INTERVAL=1;COUNT=4;BYDAY=0MO;WKST=SA',
879 '2014-08-01 00:00:00',
880 []
881 );
882
883 }
884
886
887 $this->parse(
888 'FREQ=WEEKLY;UNTIL=20131118T183000',
889 '2013-09-23 18:30:00',
890 [
891 '2013-09-23 18:30:00',
892 '2013-09-30 18:30:00',
893 '2013-10-07 18:30:00',
894 '2013-10-14 18:30:00',
895 '2013-10-21 18:30:00',
896 '2013-10-28 18:30:00',
897 '2013-11-04 18:30:00',
898 '2013-11-11 18:30:00',
899 '2013-11-18 18:30:00',
900 ],
901 null,
902 'America/New_York'
903 );
904
905 }
906
908
909 $this->parse(
910 'FREQ=DAILY;UNTIL=20140101T000000Z',
911 '2014-08-02 00:15:00',
912 [
913 '2014-08-02 00:15:00',
914 ]
915 );
916
917 }
918
919 function testIgnoredStuff() {
920
921 $this->parse(
922 'FREQ=DAILY;BYSECOND=1;BYMINUTE=1;BYYEARDAY=1;BYWEEKNO=1;COUNT=2',
923 '2014-08-02 00:15:00',
924 [
925 '2014-08-02 00:15:00',
926 '2014-08-03 00:15:00',
927 ]
928 );
929
930 }
931
933
934 $this->parse(
935 'FREQ=MONTHLY;BYDAY=-4TH,-5TH;COUNT=4',
936 '2015-01-01 00:15:00',
937 [
938 '2015-01-01 00:15:00',
939 '2015-01-08 00:15:00',
940 '2015-02-05 00:15:00',
941 '2015-03-05 00:15:00'
942 ]
943 );
944
945 }
946
951
952 $this->parse(
953 'FREQ=DAILY;BYWODAN=1',
954 '2014-08-02 00:15:00',
955 []
956 );
957
958 }
959
961
962 $parser = new RRuleIterator('FREQ=DAILY', new DateTime('2014-08-02 00:00:13'));
963 $parser->next();
964 $this->assertEquals(
965 new DateTime('2014-08-03 00:00:13'),
966 $parser->current()
967 );
968 $this->assertEquals(
969 1,
970 $parser->key()
971 );
972
973 $parser->rewind();
974
975 $this->assertEquals(
976 new DateTime('2014-08-02 00:00:13'),
977 $parser->current()
978 );
979 $this->assertEquals(
980 0,
981 $parser->key()
982 );
983
984 }
985
986 function parse($rule, $start, $expected, $fastForward = null, $tz = 'UTC') {
987
988 $dt = new DateTime($start, new DateTimeZone($tz));
989 $parser = new RRuleIterator($rule, $dt);
990
991 if ($fastForward) {
992 $parser->fastForward(new DateTime($fastForward));
993 }
994
995 $result = [];
996 while ($parser->valid()) {
997
998 $item = $parser->current();
999 $result[] = $item->format('Y-m-d H:i:s');
1000
1001 if ($parser->isInfinite() && count($result) >= count($expected)) {
1002 break;
1003 }
1004 $parser->next();
1005
1006 }
1007
1008 $this->assertEquals(
1009 $expected,
1010 $result
1011 );
1012
1013 }
1014
1015}
$parser
Definition: BPMN2Parser.php:23
$result
An exception for terminatinating execution or to throw for unit testing.
testUnsupportedPart()
@expectedException \Sabre\VObject\InvalidDataException
testFastFowardTooFar()
This bug came from a Fruux customer.
testYearlyByMonthManyInvalidValues()
@expectedException \Sabre\VObject\InvalidDataException
testYearlyByMonthEmptyValue()
@expectedException \Sabre\VObject\InvalidDataException
testYearlyByMonthInvalidValue1()
@expectedException \Sabre\VObject\InvalidDataException
testFifthTuesdayProblem()
The bug that was in the system before would fail on the 5th tuesday of the month, if the 5th tuesday ...
testByDayBadOffset()
@expectedException \Sabre\VObject\InvalidDataException
testInvalidByWeekNo()
@expectedException \Sabre\VObject\InvalidDataException
testYearlyByMonthInvalidValue2()
@expectedException \Sabre\VObject\InvalidDataException
testInvalidFreq()
@expectedException \Sabre\VObject\InvalidDataException
testYearlyByYearDayInvalid390()
@expectedException \Sabre\VObject\InvalidDataException
testZeroInterval()
Something, somewhere produced an ics with an interval set to 0.
testYearlyByYearDayInvalid0()
@expectedException \Sabre\VObject\InvalidDataException
testYearlyByMonthLoop()
This also at one point caused an infinite loop.
parse($rule, $start, $expected, $fastForward=null, $tz='UTC')
$rule
Definition: showstats.php:43
$start
Definition: bench.php:8