1<?php
2
3namespace Sabre\VObject\Recur\EventIterator;
4
5use
6    DateTime,
7    DateTimeZone,
8    Sabre\VObject\Reader;
9
10class ExpandFloatingTimesTest extends \PHPUnit_Framework_TestCase {
11
12    function testExpand() {
13
14        $input = <<<ICS
15BEGIN:VCALENDAR
16VERSION:2.0
17BEGIN:VEVENT
18UID:foo
19DTSTART:20150109T090000
20DTEND:20150109T100000
21RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20191002T070000Z;BYDAY=FR
22END:VEVENT
23END:VCALENDAR
24ICS;
25
26        $vcal = Reader::read($input);
27        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
28
29        $vcal->expand(new DateTime('2015-01-01'), new DateTime('2015-01-31'));
30
31        $result = $vcal->serialize();
32
33        $output = <<<ICS
34BEGIN:VCALENDAR
35VERSION:2.0
36BEGIN:VEVENT
37UID:foo
38DTSTART:20150109T090000Z
39DTEND:20150109T100000Z
40RECURRENCE-ID:20150109T090000Z
41END:VEVENT
42BEGIN:VEVENT
43UID:foo
44DTSTART:20150116T090000Z
45DTEND:20150116T100000Z
46RECURRENCE-ID:20150116T090000Z
47END:VEVENT
48BEGIN:VEVENT
49UID:foo
50DTSTART:20150123T090000Z
51DTEND:20150123T100000Z
52RECURRENCE-ID:20150123T090000Z
53END:VEVENT
54BEGIN:VEVENT
55UID:foo
56DTSTART:20150130T090000Z
57DTEND:20150130T100000Z
58RECURRENCE-ID:20150130T090000Z
59END:VEVENT
60END:VCALENDAR
61
62ICS;
63        $this->assertEquals($output, str_replace("\r", "", $result));
64
65    }
66
67    function testExpandWithReferenceTimezone() {
68
69        $input = <<<ICS
70BEGIN:VCALENDAR
71VERSION:2.0
72BEGIN:VEVENT
73UID:foo
74DTSTART:20150109T090000
75DTEND:20150109T100000
76RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20191002T070000Z;BYDAY=FR
77END:VEVENT
78END:VCALENDAR
79ICS;
80
81        $vcal = Reader::read($input);
82        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
83
84        $vcal->expand(new DateTime('2015-01-01'), new DateTime('2015-01-31'), new \DateTimeZone('Europe/Berlin'));
85
86        $result = $vcal->serialize();
87
88        $output = <<<ICS
89BEGIN:VCALENDAR
90VERSION:2.0
91BEGIN:VEVENT
92UID:foo
93DTSTART:20150109T080000Z
94DTEND:20150109T090000Z
95RECURRENCE-ID:20150109T080000Z
96END:VEVENT
97BEGIN:VEVENT
98UID:foo
99DTSTART:20150116T080000Z
100DTEND:20150116T090000Z
101RECURRENCE-ID:20150116T080000Z
102END:VEVENT
103BEGIN:VEVENT
104UID:foo
105DTSTART:20150123T080000Z
106DTEND:20150123T090000Z
107RECURRENCE-ID:20150123T080000Z
108END:VEVENT
109BEGIN:VEVENT
110UID:foo
111DTSTART:20150130T080000Z
112DTEND:20150130T090000Z
113RECURRENCE-ID:20150130T080000Z
114END:VEVENT
115END:VCALENDAR
116
117ICS;
118        $this->assertEquals($output, str_replace("\r", "", $result));
119
120    }
121
122}
123