ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
RDateIterator.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\VObject\Recur;
4
5use DateTimeInterface;
6use Iterator;
8
22class RDateIterator implements Iterator {
23
30 function __construct($rrule, DateTimeInterface $start) {
31
32 $this->startDate = $start;
33 $this->parseRDate($rrule);
34 $this->currentDate = clone $this->startDate;
35
36 }
37
38 /* Implementation of the Iterator interface {{{ */
39
40 function current() {
41
42 if (!$this->valid()) return;
43 return clone $this->currentDate;
44
45 }
46
52 function key() {
53
54 return $this->counter;
55
56 }
57
64 function valid() {
65
66 return ($this->counter <= count($this->dates));
67
68 }
69
75 function rewind() {
76
77 $this->currentDate = clone $this->startDate;
78 $this->counter = 0;
79
80 }
81
87 function next() {
88
89 $this->counter++;
90 if (!$this->valid()) return;
91
92 $this->currentDate =
94 $this->dates[$this->counter - 1],
95 $this->startDate->getTimezone()
96 );
97
98 }
99
100 /* End of Iterator implementation }}} */
101
107 function isInfinite() {
108
109 return false;
110
111 }
112
121 function fastForward(DateTimeInterface $dt) {
122
123 while ($this->valid() && $this->currentDate < $dt) {
124 $this->next();
125 }
126
127 }
128
136 protected $startDate;
137
144 protected $currentDate;
145
153 protected $counter = 0;
154
155 /* }}} */
156
165 protected function parseRDate($rdate) {
166
167 if (is_string($rdate)) {
168 $rdate = explode(',', $rdate);
169 }
170
171 $this->dates = $rdate;
172
173 }
174
180 protected $dates = [];
181
182}
An exception for terminatinating execution or to throw for unit testing.
static parse($date, $referenceTz=null)
Parses either a Date or DateTime, or Duration value.
__construct($rrule, DateTimeInterface $start)
Creates the Iterator.
rewind()
Resets the iterator.
next()
Goes on to the next iteration.
isInfinite()
Returns true if this recurring event never ends.
valid()
Returns whether the current item is a valid item for the recurrence iterator.
fastForward(DateTimeInterface $dt)
This method allows you to quickly go to the next occurrence after the specified date.
parseRDate($rdate)
This method receives a string from an RRULE property, and populates this class with all the values.
key()
Returns the current item number.
$start
Definition: bench.php:8