annotate plugins/libcalendaring/lib/Sabre/VObject/RecurrenceIterator.php @ 4:888e774ee983

libcalendar plugin as distributed
author Charlie Root
date Sat, 13 Jan 2018 08:57:56 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1 <?php
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
2
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6 * This class is used to determine new for a recurring event, when the next
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 * events occur.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 * This iterator may loop infinitely in the future, therefore it is important
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 * that if you use this class, you set hard limits for the amount of iterations
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 * you want to handle.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 * Note that currently there is not full support for the entire iCalendar
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 * specification, as it's very complex and contains a lot of permutations
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 * that's not yet used very often in software.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 * For the focus has been on features as they actually appear in Calendaring
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 * software, but this may well get expanded as needed / on demand
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 * The following RRULE properties are supported
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 * * UNTIL
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 * * INTERVAL
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 * * COUNT
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 * * FREQ=DAILY
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25 * * BYDAY
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 * * BYHOUR
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 * * FREQ=WEEKLY
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 * * BYDAY
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29 * * BYHOUR
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30 * * WKST
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 * * FREQ=MONTHLY
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 * * BYMONTHDAY
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33 * * BYDAY
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 * * BYSETPOS
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 * * FREQ=YEARLY
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 * * BYMONTH
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 * * BYMONTHDAY (only if BYMONTH is also set)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 * * BYDAY (only if BYMONTH is also set)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40 * Anything beyond this is 'undefined', which means that it may get ignored, or
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41 * you may get unexpected results. The effect is that in some applications the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42 * specified recurrence may look incorrect, or is missing.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 * @author Evert Pot (http://evertpot.com/)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 class RecurrenceIterator implements \Iterator {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 * The initial event date
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 * @var DateTime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 public $startDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58 * The end-date of the initial event
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60 * @var DateTime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62 public $endDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 * The 'current' recurrence.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67 * This will be increased for every iteration.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69 * @var DateTime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71 public $currentDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75 * List of dates that are excluded from the rules.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
76 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
77 * This list contains the items that have been overriden by the EXDATE
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
78 * property.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
79 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
80 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
81 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
82 public $exceptionDates = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
83
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
84 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
85 * Base event
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
86 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
87 * @var Component\VEvent
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
88 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
89 public $baseEvent;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
90
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
91 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
92 * List of dates that are overridden by other events.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
93 * Similar to $overriddenEvents, but this just contains the original dates.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
94 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
95 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
96 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
97 public $overriddenDates = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
98
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
99 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
100 * list of events that are 'overridden'.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
101 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
102 * This is an array of Component\VEvent objects.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
103 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
104 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
105 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
106 public $overriddenEvents = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
107
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
108 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
109 * Frequency is one of: secondly, minutely, hourly, daily, weekly, monthly,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
110 * yearly.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
111 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
112 * @var string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
113 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
114 public $frequency;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
115
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
116 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
117 * The last instance of this recurrence, inclusively
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
118 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
119 * @var DateTime|null
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
120 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
121 public $until;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
122
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
123 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
124 * The number of recurrences, or 'null' if infinitely recurring.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
125 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
126 * @var int
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
127 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
128 public $count;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
129
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
130 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
131 * The interval.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
132 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
133 * If for example frequency is set to daily, interval = 2 would mean every
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
134 * 2 days.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
135 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
136 * @var int
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
137 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
138 public $interval = 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
139
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
140 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
141 * Which seconds to recur.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
142 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
143 * This is an array of integers (between 0 and 60)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
144 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
145 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
146 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
147 public $bySecond;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
148
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
149 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
150 * Which minutes to recur
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
151 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
152 * This is an array of integers (between 0 and 59)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
153 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
154 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
155 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
156 public $byMinute;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
157
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
158 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
159 * Which hours to recur
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
160 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
161 * This is an array of integers (between 0 and 23)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
162 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
163 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
164 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
165 public $byHour;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
166
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
167 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
168 * Which weekdays to recur.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
169 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
170 * This is an array of weekdays
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
171 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
172 * This may also be preceeded by a positive or negative integer. If present,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
173 * this indicates the nth occurrence of a specific day within the monthly or
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
174 * yearly rrule. For instance, -2TU indicates the second-last tuesday of
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
175 * the month, or year.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
176 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
177 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
178 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
179 public $byDay;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
180
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
181 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
182 * Which days of the month to recur
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
183 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
184 * This is an array of days of the months (1-31). The value can also be
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
185 * negative. -5 for instance means the 5th last day of the month.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
186 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
187 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
188 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
189 public $byMonthDay;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
190
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
191 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
192 * Which days of the year to recur.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
193 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
194 * This is an array with days of the year (1 to 366). The values can also
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
195 * be negative. For instance, -1 will always represent the last day of the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
196 * year. (December 31st).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
197 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
198 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
199 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
200 public $byYearDay;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
201
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
202 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
203 * Which week numbers to recur.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
204 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
205 * This is an array of integers from 1 to 53. The values can also be
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
206 * negative. -1 will always refer to the last week of the year.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
207 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
208 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
209 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
210 public $byWeekNo;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
211
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
212 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
213 * Which months to recur
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
214 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
215 * This is an array of integers from 1 to 12.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
216 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
217 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
218 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
219 public $byMonth;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
220
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
221 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
222 * Which items in an existing st to recur.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
223 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
224 * These numbers work together with an existing by* rule. It specifies
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
225 * exactly which items of the existing by-rule to filter.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
226 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
227 * Valid values are 1 to 366 and -1 to -366. As an example, this can be
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
228 * used to recur the last workday of the month.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
229 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
230 * This would be done by setting frequency to 'monthly', byDay to
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
231 * 'MO,TU,WE,TH,FR' and bySetPos to -1.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
232 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
233 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
234 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
235 public $bySetPos;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
236
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
237 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
238 * When a week starts
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
239 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
240 * @var string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
241 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
242 public $weekStart = 'MO';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
243
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
244 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
245 * The current item in the list
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
246 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
247 * @var int
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
248 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
249 public $counter = 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
250
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
251 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
252 * Simple mapping from iCalendar day names to day numbers
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
253 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
254 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
255 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
256 private $dayMap = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
257 'SU' => 0,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
258 'MO' => 1,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
259 'TU' => 2,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
260 'WE' => 3,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
261 'TH' => 4,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
262 'FR' => 5,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
263 'SA' => 6,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
264 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
265
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
266 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
267 * Mappings between the day number and english day name.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
268 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
269 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
270 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
271 private $dayNames = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
272 0 => 'Sunday',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
273 1 => 'Monday',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
274 2 => 'Tuesday',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
275 3 => 'Wednesday',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
276 4 => 'Thursday',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
277 5 => 'Friday',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
278 6 => 'Saturday',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
279 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
280
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
281 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
282 * If the current iteration of the event is an overriden event, this
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
283 * property will hold the VObject
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
284 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
285 * @var Component
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
286 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
287 private $currentOverriddenEvent;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
288
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
289 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
290 * This property may contain the date of the next not-overridden event.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
291 * This date is calculated sometimes a bit early, before overridden events
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
292 * are evaluated.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
293 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
294 * @var DateTime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
295 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
296 private $nextDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
297
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
298 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
299 * This counts the number of overridden events we've handled so far
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
300 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
301 * @var int
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
302 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
303 private $handledOverridden = 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
304
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
305 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
306 * Creates the iterator
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
307 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
308 * You should pass a VCALENDAR component, as well as the UID of the event
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
309 * we're going to traverse.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
310 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
311 * @param Component $vcal
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
312 * @param string|null $uid
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
313 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
314 public function __construct(Component $vcal, $uid=null) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
315
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
316 if (is_null($uid)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
317 if ($vcal->name === 'VCALENDAR') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
318 throw new \InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
319 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
320 $components = array($vcal);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
321 $uid = (string)$vcal->uid;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
322 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
323 $components = $vcal->select('VEVENT');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
324 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
325 foreach($components as $component) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
326 if ((string)$component->uid == $uid) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
327 if (isset($component->{'RECURRENCE-ID'})) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
328 $this->overriddenEvents[$component->DTSTART->getDateTime()->getTimeStamp()] = $component;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
329 $this->overriddenDates[] = $component->{'RECURRENCE-ID'}->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
330 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
331 $this->baseEvent = $component;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
332 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
333 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
334 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
335
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
336 ksort($this->overriddenEvents);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
337
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
338 if (!$this->baseEvent) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
339 throw new \InvalidArgumentException('Could not find a base event with uid: ' . $uid);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
340 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
341
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
342 $this->startDate = clone $this->baseEvent->DTSTART->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
343
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
344 $this->endDate = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
345 if (isset($this->baseEvent->DTEND)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
346 $this->endDate = clone $this->baseEvent->DTEND->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
347 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
348 $this->endDate = clone $this->startDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
349 if (isset($this->baseEvent->DURATION)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
350 $this->endDate->add(DateTimeParser::parse($this->baseEvent->DURATION->value));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
351 } elseif ($this->baseEvent->DTSTART->getDateType()===Property\DateTime::DATE) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
352 $this->endDate->modify('+1 day');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
353 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
354 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
355 $this->currentDate = clone $this->startDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
356
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
357 $rrule = (string)$this->baseEvent->RRULE;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
358
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
359 $parts = explode(';', $rrule);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
360
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
361 // If no rrule was specified, we create a default setting
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
362 if (!$rrule) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
363 $this->frequency = 'daily';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
364 $this->count = 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
365 } else foreach($parts as $part) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
366
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
367 list($key, $value) = explode('=', $part, 2);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
368
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
369 switch(strtoupper($key)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
370
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
371 case 'FREQ' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
372 if (!in_array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
373 strtolower($value),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
374 array('secondly','minutely','hourly','daily','weekly','monthly','yearly')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
375 )) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
376 throw new \InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
377
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
378 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
379 $this->frequency = strtolower($value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
380 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
381
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
382 case 'UNTIL' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
383 $this->until = DateTimeParser::parse($value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
384
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
385 // In some cases events are generated with an UNTIL=
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
386 // parameter before the actual start of the event.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
387 //
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
388 // Not sure why this is happening. We assume that the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
389 // intention was that the event only recurs once.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
390 //
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
391 // So we are modifying the parameter so our code doesn't
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
392 // break.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
393 if($this->until < $this->baseEvent->DTSTART->getDateTime()) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
394 $this->until = $this->baseEvent->DTSTART->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
395 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
396 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
397
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
398 case 'COUNT' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
399 $this->count = (int)$value;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
400 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
401
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
402 case 'INTERVAL' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
403 $this->interval = (int)$value;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
404 if ($this->interval < 1) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
405 throw new \InvalidArgumentException('INTERVAL in RRULE must be a positive integer!');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
406 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
407 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
408
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
409 case 'BYSECOND' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
410 $this->bySecond = explode(',', $value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
411 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
412
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
413 case 'BYMINUTE' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
414 $this->byMinute = explode(',', $value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
415 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
416
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
417 case 'BYHOUR' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
418 $this->byHour = explode(',', $value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
419 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
420
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
421 case 'BYDAY' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
422 $this->byDay = explode(',', strtoupper($value));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
423 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
424
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
425 case 'BYMONTHDAY' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
426 $this->byMonthDay = explode(',', $value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
427 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
428
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
429 case 'BYYEARDAY' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
430 $this->byYearDay = explode(',', $value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
431 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
432
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
433 case 'BYWEEKNO' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
434 $this->byWeekNo = explode(',', $value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
435 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
436
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
437 case 'BYMONTH' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
438 $this->byMonth = explode(',', $value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
439 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
440
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
441 case 'BYSETPOS' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
442 $this->bySetPos = explode(',', $value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
443 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
444
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
445 case 'WKST' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
446 $this->weekStart = strtoupper($value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
447 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
448
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
449 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
450
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
451 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
452
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
453 // Parsing exception dates
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
454 if (isset($this->baseEvent->EXDATE)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
455 foreach($this->baseEvent->EXDATE as $exDate) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
456
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
457 foreach(explode(',', (string)$exDate) as $exceptionDate) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
458
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
459 $this->exceptionDates[] =
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
460 DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
461
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
462 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
463
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
464 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
465
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
466 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
467
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
468 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
469
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
470 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
471 * Returns the current item in the list
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
472 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
473 * @return DateTime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
474 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
475 public function current() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
476
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
477 if (!$this->valid()) return null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
478 return clone $this->currentDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
479
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
480 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
481
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
482 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
483 * This method returns the startdate for the current iteration of the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
484 * event.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
485 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
486 * @return DateTime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
487 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
488 public function getDtStart() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
489
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
490 if (!$this->valid()) return null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
491 return clone $this->currentDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
492
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
493 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
494
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
495 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
496 * This method returns the enddate for the current iteration of the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
497 * event.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
498 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
499 * @return DateTime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
500 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
501 public function getDtEnd() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
502
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
503 if (!$this->valid()) return null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
504 $dtEnd = clone $this->currentDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
505 $dtEnd->add( $this->startDate->diff( $this->endDate ) );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
506 return clone $dtEnd;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
507
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
508 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
509
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
510 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
511 * Returns a VEVENT object with the updated start and end date.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
512 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
513 * Any recurrence information is removed, and this function may return an
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
514 * 'overridden' event instead.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
515 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
516 * This method always returns a cloned instance.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
517 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
518 * @return Component\VEvent
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
519 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
520 public function getEventObject() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
521
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
522 if ($this->currentOverriddenEvent) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
523 return clone $this->currentOverriddenEvent;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
524 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
525 $event = clone $this->baseEvent;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
526 unset($event->RRULE);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
527 unset($event->EXDATE);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
528 unset($event->RDATE);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
529 unset($event->EXRULE);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
530
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
531 $event->DTSTART->setDateTime($this->getDTStart(), $event->DTSTART->getDateType());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
532 if (isset($event->DTEND)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
533 $event->DTEND->setDateTime($this->getDtEnd(), $event->DTSTART->getDateType());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
534 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
535 if ($this->counter > 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
536 $event->{'RECURRENCE-ID'} = (string)$event->DTSTART;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
537 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
538
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
539 return $event;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
540
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
541 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
542
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
543 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
544 * Returns the current item number
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
545 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
546 * @return int
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
547 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
548 public function key() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
549
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
550 return $this->counter;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
551
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
552 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
553
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
554 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
555 * Whether or not there is a 'next item'
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
556 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
557 * @return bool
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
558 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
559 public function valid() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
560
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
561 if (!is_null($this->count)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
562 return $this->counter < $this->count;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
563 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
564 if (!is_null($this->until) && $this->currentDate > $this->until) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
565
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
566 // Need to make sure there's no overridden events past the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
567 // until date.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
568 foreach($this->overriddenEvents as $overriddenEvent) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
569
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
570 if ($overriddenEvent->DTSTART->getDateTime() >= $this->currentDate) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
571
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
572 return true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
573 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
574 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
575 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
576 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
577 return true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
578
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
579 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
580
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
581 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
582 * Resets the iterator
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
583 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
584 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
585 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
586 public function rewind() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
587
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
588 $this->currentDate = clone $this->startDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
589 $this->counter = 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
590
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
591 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
592
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
593 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
594 * This method allows you to quickly go to the next occurrence after the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
595 * specified date.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
596 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
597 * Note that this checks the current 'endDate', not the 'stardDate'. This
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
598 * means that if you forward to January 1st, the iterator will stop at the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
599 * first event that ends *after* January 1st.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
600 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
601 * @param DateTime $dt
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
602 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
603 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
604 public function fastForward(\DateTime $dt) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
605
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
606 while($this->valid() && $this->getDTEnd() <= $dt) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
607 $this->next();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
608 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
609
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
610 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
611
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
612 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
613 * Returns true if this recurring event never ends.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
614 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
615 * @return bool
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
616 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
617 public function isInfinite() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
618
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
619 return !$this->count && !$this->until;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
620
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
621 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
622
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
623 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
624 * Goes on to the next iteration
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
625 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
626 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
627 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
628 public function next() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
629
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
630 $previousStamp = $this->currentDate->getTimeStamp();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
631
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
632 // Finding the next overridden event in line, and storing that for
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
633 // later use.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
634 $overriddenEvent = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
635 $overriddenDate = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
636 $this->currentOverriddenEvent = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
637
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
638 foreach($this->overriddenEvents as $index=>$event) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
639 if ($index > $previousStamp) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
640 $overriddenEvent = $event;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
641 $overriddenDate = clone $event->DTSTART->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
642 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
643 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
644 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
645
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
646 // If we have a stored 'next date', we will use that.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
647 if ($this->nextDate) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
648 if (!$overriddenDate || $this->nextDate < $overriddenDate) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
649 $this->currentDate = $this->nextDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
650 $currentStamp = $this->currentDate->getTimeStamp();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
651 $this->nextDate = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
652 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
653 $this->currentDate = clone $overriddenDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
654 $this->currentOverriddenEvent = $overriddenEvent;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
655 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
656 $this->counter++;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
657 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
658 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
659
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
660 while(true) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
661
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
662 // Otherwise, we find the next event in the normal RRULE
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
663 // sequence.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
664 switch($this->frequency) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
665
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
666 case 'hourly' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
667 $this->nextHourly();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
668 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
669
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
670 case 'daily' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
671 $this->nextDaily();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
672 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
673
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
674 case 'weekly' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
675 $this->nextWeekly();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
676 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
677
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
678 case 'monthly' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
679 $this->nextMonthly();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
680 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
681
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
682 case 'yearly' :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
683 $this->nextYearly();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
684 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
685
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
686 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
687 $currentStamp = $this->currentDate->getTimeStamp();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
688
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
689
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
690 // Checking exception dates
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
691 foreach($this->exceptionDates as $exceptionDate) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
692 if ($this->currentDate == $exceptionDate) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
693 $this->counter++;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
694 continue 2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
695 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
696 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
697 foreach($this->overriddenDates as $check) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
698 if ($this->currentDate == $check) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
699 continue 2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
700 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
701 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
702 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
703
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
704 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
705
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
706
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
707
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
708 // Is the date we have actually higher than the next overiddenEvent?
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
709 if ($overriddenDate && $this->currentDate > $overriddenDate) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
710 $this->nextDate = clone $this->currentDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
711 $this->currentDate = clone $overriddenDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
712 $this->currentOverriddenEvent = $overriddenEvent;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
713 $this->handledOverridden++;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
714 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
715 $this->counter++;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
716
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
717
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
718 /*
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
719 * If we have overridden events left in the queue, but our counter is
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
720 * running out, we should grab one of those.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
721 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
722 if (!is_null($overriddenEvent) && !is_null($this->count) && count($this->overriddenEvents) - $this->handledOverridden >= ($this->count - $this->counter)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
723
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
724 $this->currentOverriddenEvent = $overriddenEvent;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
725 $this->currentDate = clone $overriddenDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
726 $this->handledOverridden++;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
727
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
728 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
729
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
730 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
731
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
732 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
733 * Does the processing for advancing the iterator for hourly frequency.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
734 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
735 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
736 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
737 protected function nextHourly() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
738
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
739 if (!$this->byHour) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
740 $this->currentDate->modify('+' . $this->interval . ' hours');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
741 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
742 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
743 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
744
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
745 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
746 * Does the processing for advancing the iterator for daily frequency.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
747 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
748 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
749 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
750 protected function nextDaily() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
751
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
752 if (!$this->byHour && !$this->byDay) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
753 $this->currentDate->modify('+' . $this->interval . ' days');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
754 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
755 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
756
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
757 if (isset($this->byHour)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
758 $recurrenceHours = $this->getHours();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
759 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
760
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
761 if (isset($this->byDay)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
762 $recurrenceDays = $this->getDays();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
763 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
764
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
765 do {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
766
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
767 if ($this->byHour) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
768 if ($this->currentDate->format('G') == '23') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
769 // to obey the interval rule
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
770 $this->currentDate->modify('+' . $this->interval-1 . ' days');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
771 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
772
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
773 $this->currentDate->modify('+1 hours');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
774
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
775 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
776 $this->currentDate->modify('+' . $this->interval . ' days');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
777
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
778 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
779
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
780 // Current day of the week
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
781 $currentDay = $this->currentDate->format('w');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
782
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
783 // Current hour of the day
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
784 $currentHour = $this->currentDate->format('G');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
785
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
786 } while (($this->byDay && !in_array($currentDay, $recurrenceDays)) || ($this->byHour && !in_array($currentHour, $recurrenceHours)));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
787
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
788 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
789
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
790 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
791 * Does the processing for advancing the iterator for weekly frequency.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
792 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
793 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
794 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
795 protected function nextWeekly() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
796
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
797 if (!$this->byHour && !$this->byDay) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
798 $this->currentDate->modify('+' . $this->interval . ' weeks');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
799 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
800 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
801
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
802 if ($this->byHour) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
803 $recurrenceHours = $this->getHours();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
804 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
805
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
806 if ($this->byDay) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
807 $recurrenceDays = $this->getDays();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
808 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
809
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
810 // First day of the week:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
811 $firstDay = $this->dayMap[$this->weekStart];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
812
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
813 do {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
814
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
815 if ($this->byHour) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
816 $this->currentDate->modify('+1 hours');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
817 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
818 $this->currentDate->modify('+1 days');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
819 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
820
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
821 // Current day of the week
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
822 $currentDay = (int) $this->currentDate->format('w');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
823
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
824 // Current hour of the day
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
825 $currentHour = (int) $this->currentDate->format('G');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
826
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
827 // We need to roll over to the next week
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
828 if ($currentDay === $firstDay && (!$this->byHour || $currentHour == '0')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
829 $this->currentDate->modify('+' . $this->interval-1 . ' weeks');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
830
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
831 // We need to go to the first day of this week, but only if we
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
832 // are not already on this first day of this week.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
833 if($this->currentDate->format('w') != $firstDay) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
834 $this->currentDate->modify('last ' . $this->dayNames[$this->dayMap[$this->weekStart]]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
835 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
836 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
837
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
838 // We have a match
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
839 } while (($this->byDay && !in_array($currentDay, $recurrenceDays)) || ($this->byHour && !in_array($currentHour, $recurrenceHours)));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
840 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
841
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
842 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
843 * Does the processing for advancing the iterator for monthly frequency.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
844 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
845 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
846 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
847 protected function nextMonthly() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
848
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
849 $currentDayOfMonth = $this->currentDate->format('j');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
850 if (!$this->byMonthDay && !$this->byDay) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
851
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
852 // If the current day is higher than the 28th, rollover can
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
853 // occur to the next month. We Must skip these invalid
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
854 // entries.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
855 if ($currentDayOfMonth < 29) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
856 $this->currentDate->modify('+' . $this->interval . ' months');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
857 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
858 $increase = 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
859 do {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
860 $increase++;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
861 $tempDate = clone $this->currentDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
862 $tempDate->modify('+ ' . ($this->interval*$increase) . ' months');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
863 } while ($tempDate->format('j') != $currentDayOfMonth);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
864 $this->currentDate = $tempDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
865 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
866 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
867 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
868
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
869 while(true) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
870
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
871 $occurrences = $this->getMonthlyOccurrences();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
872
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
873 foreach($occurrences as $occurrence) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
874
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
875 // The first occurrence thats higher than the current
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
876 // day of the month wins.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
877 if ($occurrence > $currentDayOfMonth) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
878 break 2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
879 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
880
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
881 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
882
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
883 // If we made it all the way here, it means there were no
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
884 // valid occurrences, and we need to advance to the next
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
885 // month.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
886 $this->currentDate->modify('first day of this month');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
887 $this->currentDate->modify('+ ' . $this->interval . ' months');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
888
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
889 // This goes to 0 because we need to start counting at hte
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
890 // beginning.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
891 $currentDayOfMonth = 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
892
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
893 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
894
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
895 $this->currentDate->setDate($this->currentDate->format('Y'), $this->currentDate->format('n'), $occurrence);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
896
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
897 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
898
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
899 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
900 * Does the processing for advancing the iterator for yearly frequency.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
901 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
902 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
903 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
904 protected function nextYearly() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
905
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
906 $currentMonth = $this->currentDate->format('n');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
907 $currentYear = $this->currentDate->format('Y');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
908 $currentDayOfMonth = $this->currentDate->format('j');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
909
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
910 // No sub-rules, so we just advance by year
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
911 if (!$this->byMonth) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
912
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
913 // Unless it was a leap day!
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
914 if ($currentMonth==2 && $currentDayOfMonth==29) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
915
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
916 $counter = 0;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
917 do {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
918 $counter++;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
919 // Here we increase the year count by the interval, until
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
920 // we hit a date that's also in a leap year.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
921 //
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
922 // We could just find the next interval that's dividable by
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
923 // 4, but that would ignore the rule that there's no leap
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
924 // year every year that's dividable by a 100, but not by
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
925 // 400. (1800, 1900, 2100). So we just rely on the datetime
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
926 // functions instead.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
927 $nextDate = clone $this->currentDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
928 $nextDate->modify('+ ' . ($this->interval*$counter) . ' years');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
929 } while ($nextDate->format('n')!=2);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
930 $this->currentDate = $nextDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
931
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
932 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
933
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
934 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
935
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
936 // The easiest form
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
937 $this->currentDate->modify('+' . $this->interval . ' years');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
938 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
939
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
940 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
941
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
942 $currentMonth = $this->currentDate->format('n');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
943 $currentYear = $this->currentDate->format('Y');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
944 $currentDayOfMonth = $this->currentDate->format('j');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
945
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
946 $advancedToNewMonth = false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
947
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
948 // If we got a byDay or getMonthDay filter, we must first expand
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
949 // further.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
950 if ($this->byDay || $this->byMonthDay) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
951
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
952 while(true) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
953
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
954 $occurrences = $this->getMonthlyOccurrences();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
955
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
956 foreach($occurrences as $occurrence) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
957
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
958 // The first occurrence that's higher than the current
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
959 // day of the month wins.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
960 // If we advanced to the next month or year, the first
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
961 // occurrence is always correct.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
962 if ($occurrence > $currentDayOfMonth || $advancedToNewMonth) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
963 break 2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
964 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
965
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
966 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
967
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
968 // If we made it here, it means we need to advance to
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
969 // the next month or year.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
970 $currentDayOfMonth = 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
971 $advancedToNewMonth = true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
972 do {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
973
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
974 $currentMonth++;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
975 if ($currentMonth>12) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
976 $currentYear+=$this->interval;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
977 $currentMonth = 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
978 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
979 } while (!in_array($currentMonth, $this->byMonth));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
980
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
981 $this->currentDate->setDate($currentYear, $currentMonth, $currentDayOfMonth);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
982
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
983 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
984
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
985 // If we made it here, it means we got a valid occurrence
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
986 $this->currentDate->setDate($currentYear, $currentMonth, $occurrence);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
987 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
988
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
989 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
990
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
991 // These are the 'byMonth' rules, if there are no byDay or
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
992 // byMonthDay sub-rules.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
993 do {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
994
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
995 $currentMonth++;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
996 if ($currentMonth>12) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
997 $currentYear+=$this->interval;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
998 $currentMonth = 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
999 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1000 } while (!in_array($currentMonth, $this->byMonth));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1001 $this->currentDate->setDate($currentYear, $currentMonth, $currentDayOfMonth);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1002
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1003 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1004
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1005 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1006
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1007 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1008
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1009 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1010 * Returns all the occurrences for a monthly frequency with a 'byDay' or
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1011 * 'byMonthDay' expansion for the current month.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1012 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1013 * The returned list is an array of integers with the day of month (1-31).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1014 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1015 * @return array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1016 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1017 protected function getMonthlyOccurrences() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1018
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1019 $startDate = clone $this->currentDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1020
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1021 $byDayResults = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1022
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1023 // Our strategy is to simply go through the byDays, advance the date to
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1024 // that point and add it to the results.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1025 if ($this->byDay) foreach($this->byDay as $day) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1026
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1027 $dayName = $this->dayNames[$this->dayMap[substr($day,-2)]];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1028
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1029 // Dayname will be something like 'wednesday'. Now we need to find
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1030 // all wednesdays in this month.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1031 $dayHits = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1032
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1033 $checkDate = clone $startDate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1034 $checkDate->modify('first day of this month');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1035 $checkDate->modify($dayName);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1036
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1037 do {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1038 $dayHits[] = $checkDate->format('j');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1039 $checkDate->modify('next ' . $dayName);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1040 } while ($checkDate->format('n') === $startDate->format('n'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1041
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1042 // So now we have 'all wednesdays' for month. It is however
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1043 // possible that the user only really wanted the 1st, 2nd or last
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1044 // wednesday.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1045 if (strlen($day)>2) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1046 $offset = (int)substr($day,0,-2);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1047
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1048 if ($offset>0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1049 // It is possible that the day does not exist, such as a
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1050 // 5th or 6th wednesday of the month.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1051 if (isset($dayHits[$offset-1])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1052 $byDayResults[] = $dayHits[$offset-1];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1053 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1054 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1055
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1056 // if it was negative we count from the end of the array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1057 $byDayResults[] = $dayHits[count($dayHits) + $offset];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1058 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1059 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1060 // There was no counter (first, second, last wednesdays), so we
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1061 // just need to add the all to the list).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1062 $byDayResults = array_merge($byDayResults, $dayHits);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1063
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1064 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1065
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1066 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1067
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1068 $byMonthDayResults = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1069 if ($this->byMonthDay) foreach($this->byMonthDay as $monthDay) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1070
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1071 // Removing values that are out of range for this month
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1072 if ($monthDay > $startDate->format('t') ||
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1073 $monthDay < 0-$startDate->format('t')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1074 continue;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1075 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1076 if ($monthDay>0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1077 $byMonthDayResults[] = $monthDay;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1078 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1079 // Negative values
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1080 $byMonthDayResults[] = $startDate->format('t') + 1 + $monthDay;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1081 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1082 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1083
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1084 // If there was just byDay or just byMonthDay, they just specify our
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1085 // (almost) final list. If both were provided, then byDay limits the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1086 // list.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1087 if ($this->byMonthDay && $this->byDay) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1088 $result = array_intersect($byMonthDayResults, $byDayResults);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1089 } elseif ($this->byMonthDay) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1090 $result = $byMonthDayResults;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1091 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1092 $result = $byDayResults;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1093 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1094 $result = array_unique($result);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1095 sort($result, SORT_NUMERIC);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1096
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1097 // The last thing that needs checking is the BYSETPOS. If it's set, it
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1098 // means only certain items in the set survive the filter.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1099 if (!$this->bySetPos) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1100 return $result;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1101 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1102
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1103 $filteredResult = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1104 foreach($this->bySetPos as $setPos) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1105
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1106 if ($setPos<0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1107 $setPos = count($result)-($setPos+1);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1108 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1109 if (isset($result[$setPos-1])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1110 $filteredResult[] = $result[$setPos-1];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1111 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1112 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1113
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1114 sort($filteredResult, SORT_NUMERIC);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1115 return $filteredResult;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1116
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1117 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1118
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1119 protected function getHours()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1120 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1121 $recurrenceHours = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1122 foreach($this->byHour as $byHour) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1123 $recurrenceHours[] = $byHour;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1124 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1125
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1126 return $recurrenceHours;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1127 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1128
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1129 protected function getDays()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1130 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1131 $recurrenceDays = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1132 foreach($this->byDay as $byDay) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1133
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1134 // The day may be preceeded with a positive (+n) or
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1135 // negative (-n) integer. However, this does not make
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1136 // sense in 'weekly' so we ignore it here.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1137 $recurrenceDays[] = $this->dayMap[substr($byDay,-2)];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1138
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1139 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1140
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1141 return $recurrenceDays;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1142 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1143 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1144