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