annotate vendor/sabre/vobject/lib/Recur/RRuleIterator.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject\Recur;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 use DateTime;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 use InvalidArgumentException;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 use Iterator;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 use Sabre\VObject\DateTimeParser;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 use Sabre\VObject\Property;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 * RRuleParser
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 * This class receives an RRULE string, and allows you to iterate to get a list
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 * of dates in that recurrence.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 * For instance, passing: FREQ=DAILY;LIMIT=5 will cause the iterator to contain
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 * 5 items, one for each day.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 class RRuleIterator implements Iterator {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 * Creates the Iterator
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 * @param string|array $rrule
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 * @param DateTime $start
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 public function __construct($rrule, DateTime $start) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 $this->startDate = $start;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 $this->parseRRule($rrule);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 $this->currentDate = clone $this->startDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41 /* Implementation of the Iterator interface {{{ */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 public function current() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 if (!$this->valid()) return null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 return clone $this->currentDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 * Returns the current item number
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 * @return int
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 public function key() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 return $this->counter;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 * Returns whether the current item is a valid item for the recurrence
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 * iterator. This will return false if we've gone beyond the UNTIL or COUNT
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 * statements.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 * @return bool
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 public function valid() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 if (!is_null($this->count)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 return $this->counter < $this->count;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 return is_null($this->until) || $this->currentDate <= $this->until;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 * Resets the iterator
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 public function rewind() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 $this->currentDate = clone $this->startDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 $this->counter = 0;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 * Goes on to the next iteration
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 public function next() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 $previousStamp = $this->currentDate->getTimeStamp();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98 // Otherwise, we find the next event in the normal RRULE
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99 // sequence.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 switch($this->frequency) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 case 'hourly' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103 $this->nextHourly();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106 case 'daily' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107 $this->nextDaily();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110 case 'weekly' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111 $this->nextWeekly();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 case 'monthly' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115 $this->nextMonthly();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118 case 'yearly' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119 $this->nextYearly();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123 $this->counter++;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
124
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
125 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
126
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127 /* End of Iterator implementation }}} */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130 * Returns true if this recurring event never ends.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132 * @return bool
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134 public function isInfinite() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
136 return !$this->count && !$this->until;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
137
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
138 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
139
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
140 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141 * This method allows you to quickly go to the next occurrence after the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142 * specified date.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144 * @param DateTime $dt
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147 public function fastForward(\DateTime $dt) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149 while($this->valid() && $this->currentDate < $dt ) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 $this->next();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156 * The reference start date/time for the rrule.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158 * All calculations are based on this initial date.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160 * @var DateTime
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162 protected $startDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165 * The date of the current iteration. You can get this by calling
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166 * ->current().
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168 * @var DateTime
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170 protected $currentDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173 * Frequency is one of: secondly, minutely, hourly, daily, weekly, monthly,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174 * yearly.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176 * @var string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178 protected $frequency;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181 * The number of recurrences, or 'null' if infinitely recurring.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183 * @var int
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
184 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
185 protected $count;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
186
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
187 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
188 * The interval.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
189 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
190 * If for example frequency is set to daily, interval = 2 would mean every
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
191 * 2 days.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193 * @var int
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195 protected $interval = 1;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198 * The last instance of this recurrence, inclusively
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 * @var \DateTime|null
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202 protected $until;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205 * Which seconds to recur.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207 * This is an array of integers (between 0 and 60)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211 protected $bySecond;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214 * Which minutes to recur
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216 * This is an array of integers (between 0 and 59)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220 protected $byMinute;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223 * Which hours to recur
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225 * This is an array of integers (between 0 and 23)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229 protected $byHour;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232 * The current item in the list.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 * You can get this number with the key() method.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236 * @var int
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238 protected $counter = 0;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241 * Which weekdays to recur.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243 * This is an array of weekdays
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
244 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
245 * This may also be preceeded by a positive or negative integer. If present,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
246 * this indicates the nth occurrence of a specific day within the monthly or
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
247 * yearly rrule. For instance, -2TU indicates the second-last tuesday of
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248 * the month, or year.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252 protected $byDay;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
253
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
254 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
255 * Which days of the month to recur
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
256 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
257 * This is an array of days of the months (1-31). The value can also be
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
258 * negative. -5 for instance means the 5th last day of the month.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
259 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
260 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
262 protected $byMonthDay;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
263
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
264 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
265 * Which days of the year to recur.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
266 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
267 * This is an array with days of the year (1 to 366). The values can also
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
268 * be negative. For instance, -1 will always represent the last day of the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
269 * year. (December 31st).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
270 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
271 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
272 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
273 protected $byYearDay;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
274
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
275 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
276 * Which week numbers to recur.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
277 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
278 * This is an array of integers from 1 to 53. The values can also be
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
279 * negative. -1 will always refer to the last week of the year.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
280 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
281 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
282 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
283 protected $byWeekNo;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
284
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
285 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
286 * Which months to recur.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
287 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
288 * This is an array of integers from 1 to 12.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
289 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
290 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
291 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
292 protected $byMonth;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
293
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
294 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
295 * Which items in an existing st to recur.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
296 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
297 * These numbers work together with an existing by* rule. It specifies
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
298 * exactly which items of the existing by-rule to filter.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
299 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
300 * Valid values are 1 to 366 and -1 to -366. As an example, this can be
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
301 * used to recur the last workday of the month.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
302 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
303 * This would be done by setting frequency to 'monthly', byDay to
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
304 * 'MO,TU,WE,TH,FR' and bySetPos to -1.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
305 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
306 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
307 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
308 protected $bySetPos;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
309
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
310 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
311 * When the week starts.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
312 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
313 * @var string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
314 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
315 protected $weekStart = 'MO';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
316
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
317 /* Functions that advance the iterator {{{ */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
318
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
319 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
320 * Does the processing for advancing the iterator for hourly frequency.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
321 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
322 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
323 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
324 protected function nextHourly() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
325
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
326 $this->currentDate->modify('+' . $this->interval . ' hours');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
327
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
328 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
329
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
330 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
331 * Does the processing for advancing the iterator for daily frequency.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
332 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
333 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
334 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
335 protected function nextDaily() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
336
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
337 if (!$this->byHour && !$this->byDay) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
338 $this->currentDate->modify('+' . $this->interval . ' days');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
339 return;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
340 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
341
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
342 if (isset($this->byHour)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
343 $recurrenceHours = $this->getHours();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
344 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
345
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
346 if (isset($this->byDay)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
347 $recurrenceDays = $this->getDays();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
348 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
349
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
350 if (isset($this->byMonth)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
351 $recurrenceMonths = $this->getMonths();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
352 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
353
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
354 do {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
355 if ($this->byHour) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
356 if ($this->currentDate->format('G') == '23') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
357 // to obey the interval rule
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
358 $this->currentDate->modify('+' . $this->interval-1 . ' days');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
359 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
360
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
361 $this->currentDate->modify('+1 hours');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
362
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
363 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
364 $this->currentDate->modify('+' . $this->interval . ' days');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
365
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
366 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
367
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
368 // Current month of the year
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
369 $currentMonth = $this->currentDate->format('n');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
370
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
371 // Current day of the week
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
372 $currentDay = $this->currentDate->format('w');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
373
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
374 // Current hour of the day
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
375 $currentHour = $this->currentDate->format('G');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
376
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
377 } while (
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
378 ($this->byDay && !in_array($currentDay, $recurrenceDays)) ||
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
379 ($this->byHour && !in_array($currentHour, $recurrenceHours)) ||
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
380 ($this->byMonth && !in_array($currentMonth, $recurrenceMonths))
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
381 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
382
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
383 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
384
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
385 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
386 * Does the processing for advancing the iterator for weekly frequency.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
387 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
388 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
389 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
390 protected function nextWeekly() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
391
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
392 if (!$this->byHour && !$this->byDay) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
393 $this->currentDate->modify('+' . $this->interval . ' weeks');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
394 return;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
395 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
396
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
397 if ($this->byHour) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
398 $recurrenceHours = $this->getHours();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
399 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
400
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
401 if ($this->byDay) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
402 $recurrenceDays = $this->getDays();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
403 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
404
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
405 // First day of the week:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
406 $firstDay = $this->dayMap[$this->weekStart];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
407
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
408 do {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
409
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
410 if ($this->byHour) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
411 $this->currentDate->modify('+1 hours');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
412 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
413 $this->currentDate->modify('+1 days');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
414 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
415
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
416 // Current day of the week
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
417 $currentDay = (int) $this->currentDate->format('w');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
418
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
419 // Current hour of the day
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
420 $currentHour = (int) $this->currentDate->format('G');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
421
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
422 // We need to roll over to the next week
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
423 if ($currentDay === $firstDay && (!$this->byHour || $currentHour == '0')) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
424 $this->currentDate->modify('+' . $this->interval-1 . ' weeks');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
425
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
426 // We need to go to the first day of this week, but only if we
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
427 // are not already on this first day of this week.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
428 if($this->currentDate->format('w') != $firstDay) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
429 $this->currentDate->modify('last ' . $this->dayNames[$this->dayMap[$this->weekStart]]);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
430 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
431 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
432
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
433 // We have a match
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
434 } while (($this->byDay && !in_array($currentDay, $recurrenceDays)) || ($this->byHour && !in_array($currentHour, $recurrenceHours)));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
435 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
436
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
437 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
438 * Does the processing for advancing the iterator for monthly frequency.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
439 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
440 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
441 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
442 protected function nextMonthly() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
443
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
444 $currentDayOfMonth = $this->currentDate->format('j');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
445 if (!$this->byMonthDay && !$this->byDay) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
446
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
447 // If the current day is higher than the 28th, rollover can
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
448 // occur to the next month. We Must skip these invalid
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
449 // entries.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
450 if ($currentDayOfMonth < 29) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
451 $this->currentDate->modify('+' . $this->interval . ' months');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
452 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
453 $increase = 0;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
454 do {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
455 $increase++;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
456 $tempDate = clone $this->currentDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
457 $tempDate->modify('+ ' . ($this->interval*$increase) . ' months');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
458 } while ($tempDate->format('j') != $currentDayOfMonth);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
459 $this->currentDate = $tempDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
460 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
461 return;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
462 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
463
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
464 while(true) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
465
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
466 $occurrences = $this->getMonthlyOccurrences();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
467
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
468 foreach($occurrences as $occurrence) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
469
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
470 // The first occurrence thats higher than the current
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
471 // day of the month wins.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
472 if ($occurrence > $currentDayOfMonth) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
473 break 2;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
474 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
475
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
476 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
477
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
478 // If we made it all the way here, it means there were no
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
479 // valid occurrences, and we need to advance to the next
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
480 // month.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
481 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
482 // This line does not currently work in hhvm. Temporary workaround
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
483 // follows:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
484 // $this->currentDate->modify('first day of this month');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
485 $this->currentDate = new \DateTime($this->currentDate->format('Y-m-1 H:i:s'), $this->currentDate->getTimezone());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
486 // end of workaround
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
487 $this->currentDate->modify('+ ' . $this->interval . ' months');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
488
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
489 // This goes to 0 because we need to start counting at the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
490 // beginning.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
491 $currentDayOfMonth = 0;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
492
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
493 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
494
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
495 $this->currentDate->setDate($this->currentDate->format('Y'), $this->currentDate->format('n'), $occurrence);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
496
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
497 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
498
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
499 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
500 * Does the processing for advancing the iterator for yearly frequency.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
501 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
502 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
503 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
504 protected function nextYearly() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
505
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
506 $currentMonth = $this->currentDate->format('n');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
507 $currentYear = $this->currentDate->format('Y');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
508 $currentDayOfMonth = $this->currentDate->format('j');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
509
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
510 // No sub-rules, so we just advance by year
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
511 if (!$this->byMonth) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
512
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
513 // Unless it was a leap day!
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
514 if ($currentMonth==2 && $currentDayOfMonth==29) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
515
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
516 $counter = 0;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
517 do {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
518 $counter++;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
519 // Here we increase the year count by the interval, until
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
520 // we hit a date that's also in a leap year.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
521 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
522 // We could just find the next interval that's dividable by
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
523 // 4, but that would ignore the rule that there's no leap
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
524 // year every year that's dividable by a 100, but not by
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
525 // 400. (1800, 1900, 2100). So we just rely on the datetime
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
526 // functions instead.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
527 $nextDate = clone $this->currentDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
528 $nextDate->modify('+ ' . ($this->interval*$counter) . ' years');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
529 } while ($nextDate->format('n')!=2);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
530 $this->currentDate = $nextDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
531
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
532 return;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
533
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
534 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
535
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
536 // The easiest form
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
537 $this->currentDate->modify('+' . $this->interval . ' years');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
538 return;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
539
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
540 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
541
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
542 $currentMonth = $this->currentDate->format('n');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
543 $currentYear = $this->currentDate->format('Y');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
544 $currentDayOfMonth = $this->currentDate->format('j');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
545
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
546 $advancedToNewMonth = false;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
547
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
548 // If we got a byDay or getMonthDay filter, we must first expand
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
549 // further.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
550 if ($this->byDay || $this->byMonthDay) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
551
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
552 while(true) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
553
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
554 $occurrences = $this->getMonthlyOccurrences();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
555
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
556 foreach($occurrences as $occurrence) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
557
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
558 // The first occurrence that's higher than the current
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
559 // day of the month wins.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
560 // If we advanced to the next month or year, the first
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
561 // occurrence is always correct.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
562 if ($occurrence > $currentDayOfMonth || $advancedToNewMonth) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
563 break 2;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
564 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
565
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
566 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
567
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
568 // If we made it here, it means we need to advance to
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
569 // the next month or year.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
570 $currentDayOfMonth = 1;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
571 $advancedToNewMonth = true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
572 do {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
573
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
574 $currentMonth++;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
575 if ($currentMonth>12) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
576 $currentYear+=$this->interval;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
577 $currentMonth = 1;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
578 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
579 } while (!in_array($currentMonth, $this->byMonth));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
580
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
581 $this->currentDate->setDate($currentYear, $currentMonth, $currentDayOfMonth);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
582
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
583 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
584
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
585 // If we made it here, it means we got a valid occurrence
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
586 $this->currentDate->setDate($currentYear, $currentMonth, $occurrence);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
587 return;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
588
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
589 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
590
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
591 // These are the 'byMonth' rules, if there are no byDay or
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
592 // byMonthDay sub-rules.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
593 do {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
594
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
595 $currentMonth++;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
596 if ($currentMonth>12) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
597 $currentYear+=$this->interval;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
598 $currentMonth = 1;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
599 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
600 } while (!in_array($currentMonth, $this->byMonth));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
601 $this->currentDate->setDate($currentYear, $currentMonth, $currentDayOfMonth);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
602
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
603 return;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
604
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
605 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
606
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
607 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
608
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
609 /* }}} */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
610
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
611 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
612 * This method receives a string from an RRULE property, and populates this
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
613 * class with all the values.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
614 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
615 * @param string|array $rrule
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
616 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
617 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
618 protected function parseRRule($rrule) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
619
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
620 if (is_string($rrule)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
621 $rrule = Property\ICalendar\Recur::stringToArray($rrule);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
622 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
623
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
624 foreach($rrule as $key=>$value) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
625
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
626 $key = strtoupper($key);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
627 switch($key) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
628
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
629 case 'FREQ' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
630 $value = strtolower($value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
631 if (!in_array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
632 $value,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
633 array('secondly','minutely','hourly','daily','weekly','monthly','yearly')
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
634 )) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
635 throw new InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
636 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
637 $this->frequency = $value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
638 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
639
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
640 case 'UNTIL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
641 $this->until = DateTimeParser::parse($value, $this->startDate->getTimezone());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
642
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
643 // In some cases events are generated with an UNTIL=
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
644 // parameter before the actual start of the event.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
645 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
646 // Not sure why this is happening. We assume that the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
647 // intention was that the event only recurs once.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
648 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
649 // So we are modifying the parameter so our code doesn't
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
650 // break.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
651 if($this->until < $this->startDate) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
652 $this->until = $this->startDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
653 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
654 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
655
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
656 case 'INTERVAL' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
657 // No break
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
658
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
659 case 'COUNT' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
660 $val = (int)$value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
661 if ($val < 1) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
662 throw new \InvalidArgumentException(strtoupper($key) . ' in RRULE must be a positive integer!');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
663 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
664 $key = strtolower($key);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
665 $this->$key = $val;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
666 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
667
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
668 case 'BYSECOND' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
669 $this->bySecond = (array)$value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
670 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
671
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
672 case 'BYMINUTE' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
673 $this->byMinute = (array)$value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
674 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
675
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
676 case 'BYHOUR' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
677 $this->byHour = (array)$value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
678 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
679
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
680 case 'BYDAY' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
681 $value = (array)$value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
682 foreach($value as $part) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
683 if (!preg_match('#^ (-|\+)? ([1-5])? (MO|TU|WE|TH|FR|SA|SU) $# xi', $part)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
684 throw new \InvalidArgumentException('Invalid part in BYDAY clause: ' . $part);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
685 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
686 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
687 $this->byDay = $value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
688 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
689
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
690 case 'BYMONTHDAY' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
691 $this->byMonthDay = (array)$value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
692 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
693
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
694 case 'BYYEARDAY' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
695 $this->byYearDay = (array)$value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
696 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
697
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
698 case 'BYWEEKNO' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
699 $this->byWeekNo = (array)$value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
700 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
701
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
702 case 'BYMONTH' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
703 $this->byMonth = (array)$value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
704 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
705
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
706 case 'BYSETPOS' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
707 $this->bySetPos = (array)$value;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
708 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
709
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
710 case 'WKST' :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
711 $this->weekStart = strtoupper($value);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
712 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
713
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
714 default:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
715 throw new \InvalidArgumentException('Not supported: ' . strtoupper($key));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
716
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
717 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
718
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
719 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
720
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
721 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
722
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
723 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
724 * Mappings between the day number and english day name.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
725 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
726 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
727 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
728 protected $dayNames = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
729 0 => 'Sunday',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
730 1 => 'Monday',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
731 2 => 'Tuesday',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
732 3 => 'Wednesday',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
733 4 => 'Thursday',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
734 5 => 'Friday',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
735 6 => 'Saturday',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
736 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
737
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
738 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
739 * Returns all the occurrences for a monthly frequency with a 'byDay' or
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
740 * 'byMonthDay' expansion for the current month.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
741 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
742 * The returned list is an array of integers with the day of month (1-31).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
743 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
744 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
745 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
746 protected function getMonthlyOccurrences() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
747
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
748 $startDate = clone $this->currentDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
749
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
750 $byDayResults = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
751
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
752 // Our strategy is to simply go through the byDays, advance the date to
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
753 // that point and add it to the results.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
754 if ($this->byDay) foreach($this->byDay as $day) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
755
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
756 $dayName = $this->dayNames[$this->dayMap[substr($day,-2)]];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
757
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
758
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
759 // Dayname will be something like 'wednesday'. Now we need to find
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
760 // all wednesdays in this month.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
761 $dayHits = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
762
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
763 // workaround for missing 'first day of the month' support in hhvm
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
764 $checkDate = new \DateTime($startDate->format('Y-m-1'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
765 // workaround modify always advancing the date even if the current day is a $dayName in hhvm
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
766 if ($checkDate->format('l') !== $dayName) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
767 $checkDate->modify($dayName);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
768 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
769
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
770 do {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
771 $dayHits[] = $checkDate->format('j');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
772 $checkDate->modify('next ' . $dayName);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
773 } while ($checkDate->format('n') === $startDate->format('n'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
774
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
775 // So now we have 'all wednesdays' for month. It is however
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
776 // possible that the user only really wanted the 1st, 2nd or last
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
777 // wednesday.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
778 if (strlen($day)>2) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
779 $offset = (int)substr($day,0,-2);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
780
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
781 if ($offset>0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
782 // It is possible that the day does not exist, such as a
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
783 // 5th or 6th wednesday of the month.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
784 if (isset($dayHits[$offset-1])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
785 $byDayResults[] = $dayHits[$offset-1];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
786 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
787 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
788
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
789 // if it was negative we count from the end of the array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
790 $byDayResults[] = $dayHits[count($dayHits) + $offset];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
791 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
792 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
793 // There was no counter (first, second, last wednesdays), so we
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
794 // just need to add the all to the list).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
795 $byDayResults = array_merge($byDayResults, $dayHits);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
796
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
797 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
798
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
799 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
800
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
801 $byMonthDayResults = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
802 if ($this->byMonthDay) foreach($this->byMonthDay as $monthDay) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
803
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
804 // Removing values that are out of range for this month
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
805 if ($monthDay > $startDate->format('t') ||
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
806 $monthDay < 0-$startDate->format('t')) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
807 continue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
808 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
809 if ($monthDay>0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
810 $byMonthDayResults[] = $monthDay;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
811 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
812 // Negative values
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
813 $byMonthDayResults[] = $startDate->format('t') + 1 + $monthDay;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
814 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
815 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
816
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
817 // If there was just byDay or just byMonthDay, they just specify our
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
818 // (almost) final list. If both were provided, then byDay limits the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
819 // list.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
820 if ($this->byMonthDay && $this->byDay) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
821 $result = array_intersect($byMonthDayResults, $byDayResults);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
822 } elseif ($this->byMonthDay) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
823 $result = $byMonthDayResults;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
824 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
825 $result = $byDayResults;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
826 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
827 $result = array_unique($result);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
828 sort($result, SORT_NUMERIC);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
829
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
830 // The last thing that needs checking is the BYSETPOS. If it's set, it
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
831 // means only certain items in the set survive the filter.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
832 if (!$this->bySetPos) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
833 return $result;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
834 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
835
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
836 $filteredResult = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
837 foreach($this->bySetPos as $setPos) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
838
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
839 if ($setPos<0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
840 $setPos = count($result)-($setPos+1);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
841 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
842 if (isset($result[$setPos-1])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
843 $filteredResult[] = $result[$setPos-1];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
844 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
845 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
846
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
847 sort($filteredResult, SORT_NUMERIC);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
848 return $filteredResult;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
849
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
850 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
851
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
852 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
853 * Simple mapping from iCalendar day names to day numbers
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
854 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
855 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
856 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
857 protected $dayMap = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
858 'SU' => 0,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
859 'MO' => 1,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
860 'TU' => 2,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
861 'WE' => 3,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
862 'TH' => 4,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
863 'FR' => 5,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
864 'SA' => 6,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
865 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
866
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
867 protected function getHours()
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
868 {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
869 $recurrenceHours = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
870 foreach($this->byHour as $byHour) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
871 $recurrenceHours[] = $byHour;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
872 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
873
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
874 return $recurrenceHours;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
875 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
876
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
877 protected function getDays() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
878
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
879 $recurrenceDays = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
880 foreach($this->byDay as $byDay) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
881
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
882 // The day may be preceeded with a positive (+n) or
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
883 // negative (-n) integer. However, this does not make
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
884 // sense in 'weekly' so we ignore it here.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
885 $recurrenceDays[] = $this->dayMap[substr($byDay,-2)];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
886
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
887 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
888
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
889 return $recurrenceDays;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
890 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
891
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
892 protected function getMonths() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
893
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
894 $recurrenceMonths = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
895 foreach($this->byMonth as $byMonth) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
896 $recurrenceMonths[] = $byMonth;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
897 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
898
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
899 return $recurrenceMonths;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
900 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
901 }