1<?php
2
3namespace Sabre\VObject\Recur;
4
5use DateTimeImmutable;
6use DateTimeZone;
7
8class RDateIteratorTest extends \PHPUnit_Framework_TestCase {
9
10    function testSimple() {
11
12        $utc = new DateTimeZone('UTC');
13        $it = new RDateIterator('20140901T000000Z,20141001T000000Z', new DateTimeImmutable('2014-08-01 00:00:00', $utc));
14
15        $expected = [
16            new DateTimeImmutable('2014-08-01 00:00:00', $utc),
17            new DateTimeImmutable('2014-09-01 00:00:00', $utc),
18            new DateTimeImmutable('2014-10-01 00:00:00', $utc),
19        ];
20
21        $this->assertEquals(
22            $expected,
23            iterator_to_array($it)
24        );
25
26        $this->assertFalse($it->isInfinite());
27
28    }
29
30    function testTimezone() {
31
32        $tz = new DateTimeZone('Europe/Berlin');
33        $it = new RDateIterator('20140901T000000,20141001T000000', new DateTimeImmutable('2014-08-01 00:00:00', $tz));
34
35        $expected = [
36            new DateTimeImmutable('2014-08-01 00:00:00', $tz),
37            new DateTimeImmutable('2014-09-01 00:00:00', $tz),
38            new DateTimeImmutable('2014-10-01 00:00:00', $tz),
39        ];
40
41        $this->assertEquals(
42            $expected,
43            iterator_to_array($it)
44        );
45
46
47        $this->assertFalse($it->isInfinite());
48
49    }
50
51
52    function testFastForward() {
53
54        $utc = new DateTimeZone('UTC');
55        $it = new RDateIterator('20140901T000000Z,20141001T000000Z', new DateTimeImmutable('2014-08-01 00:00:00', $utc));
56
57        $it->fastForward(new DateTimeImmutable('2014-08-15 00:00:00'));
58
59        $result = [];
60        while ($it->valid()) {
61            $result[] = $it->current();
62            $it->next();
63        }
64
65        $expected = [
66            new DateTimeImmutable('2014-09-01 00:00:00', $utc),
67            new DateTimeImmutable('2014-10-01 00:00:00', $utc),
68        ];
69
70        $this->assertEquals(
71            $expected,
72            $result
73        );
74
75        $this->assertFalse($it->isInfinite());
76
77    }
78}
79