1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Test Date Repeat calculations.
|
6
|
*/
|
7
|
/**
|
8
|
*
|
9
|
*/
|
10
|
class DateRepeatTestCase extends DrupalWebTestCase {
|
11
|
public static function getInfo() {
|
12
|
return array(
|
13
|
'name' => t('Date Repeat'),
|
14
|
'description' => t('Test Date Repeat functions to create arrays of dates from iCal rules.') ,
|
15
|
'group' => t('Date'),
|
16
|
);
|
17
|
}
|
18
|
|
19
|
/**
|
20
|
* Implements setUp().
|
21
|
*/
|
22
|
public function setUp(array $modules = array()) {
|
23
|
// Load the date_repeat module.
|
24
|
$modules[] = 'date_api';
|
25
|
$modules[] = 'date_repeat';
|
26
|
parent::setUp($modules);
|
27
|
}
|
28
|
|
29
|
public function testDateRepeat() {
|
30
|
require_once './' . drupal_get_path('module', 'date_api') . '/date_api_ical.inc';
|
31
|
require_once './' . drupal_get_path('module', 'date_repeat') . '/date_repeat_calc.inc';
|
32
|
|
33
|
// Examples adapted from http://www.faqs.org/rfcs/rfc2445.html and
|
34
|
// http://www.kanzaki.com/docs/ical/rrule.html.
|
35
|
// Invalid value:
|
36
|
$start = "1997-09-02 09:00:00";
|
37
|
$end = "1997-09-30 09:00:00";
|
38
|
$rule = "RRULE:FREQ=NONE;INTERVAL=0;COUNT=10";
|
39
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
40
|
// should be (1997 9:00 AM EDT)September 2-11
|
41
|
$shouldbe = '';
|
42
|
$result = implode(', ', $dates);
|
43
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
44
|
|
45
|
// Daily for 10 occurrences:
|
46
|
$start = "1997-09-02 09:00:00";
|
47
|
$end = "1997-09-30 09:00:00";
|
48
|
$rule = "RRULE:FREQ=DAILY;COUNT=10";
|
49
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
50
|
// should be (1997 9:00 AM EDT)September 2-11
|
51
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-03 09:00:00, 1997-09-04 09:00:00, 1997-09-05 09:00:00, 1997-09-06 09:00:00, 1997-09-07 09:00:00, 1997-09-08 09:00:00, 1997-09-09 09:00:00, 1997-09-10 09:00:00, 1997-09-11 09:00:00';
|
52
|
$result = implode(', ', $dates);
|
53
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
54
|
|
55
|
// Daily until September 24, 1997:
|
56
|
$start = "1997-09-02 09:00:00";
|
57
|
$end = "1997-09-30 09:00:00";
|
58
|
$rule = "RRULE:FREQ=DAILY;UNTIL=19970924T000000Z";
|
59
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
60
|
// should be (1997 9:00 AM EDT)September 2-23
|
61
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-03 09:00:00, 1997-09-04 09:00:00, 1997-09-05 09:00:00, 1997-09-06 09:00:00, 1997-09-07 09:00:00, 1997-09-08 09:00:00, 1997-09-09 09:00:00, 1997-09-10 09:00:00, 1997-09-11 09:00:00, 1997-09-12 09:00:00, 1997-09-13 09:00:00, 1997-09-14 09:00:00, 1997-09-15 09:00:00, 1997-09-16 09:00:00, 1997-09-17 09:00:00, 1997-09-18 09:00:00, 1997-09-19 09:00:00, 1997-09-20 09:00:00, 1997-09-21 09:00:00, 1997-09-22 09:00:00, 1997-09-23 09:00:00';
|
62
|
$result = implode(', ', $dates);
|
63
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
64
|
|
65
|
// Every other day - until September 30:
|
66
|
$start = "1997-09-02 09:00:00";
|
67
|
$end = "1997-09-30 09:00:00";
|
68
|
$rule = "RRULE:FREQ=DAILY;INTERVAL=2";
|
69
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
70
|
// should be (1997 9:00 AM EDT)September2,4,6,8...24,26,28,30;
|
71
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-04 09:00:00, 1997-09-06 09:00:00, 1997-09-08 09:00:00, 1997-09-10 09:00:00, 1997-09-12 09:00:00, 1997-09-14 09:00:00, 1997-09-16 09:00:00, 1997-09-18 09:00:00, 1997-09-20 09:00:00, 1997-09-22 09:00:00, 1997-09-24 09:00:00, 1997-09-26 09:00:00, 1997-09-28 09:00:00, 1997-09-30 09:00:00';
|
72
|
$result = implode(', ', $dates);
|
73
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
74
|
|
75
|
// Every 10 days, 2 occurrences:
|
76
|
$start = "1997-09-02 09:00:00";
|
77
|
$end = "1997-09-30 09:00:00";
|
78
|
$rule = "RRULE:FREQ=DAILY;INTERVAL=10;COUNT=2";
|
79
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
80
|
// should be (1997 9:00 AM EDT)September 2,12
|
81
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-12 09:00:00';
|
82
|
$result = implode(', ', $dates);
|
83
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
84
|
|
85
|
// Weekly for 3 occurrences.
|
86
|
$start = "1997-09-02 09:00:00";
|
87
|
$end = "1997-09-30 09:00:00";
|
88
|
$rule = "RRULE:FREQ=WEEKLY;COUNT=3";
|
89
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
90
|
// should be (1997 9:00 AM EDT)September 2,9,16
|
91
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-09 09:00:00, 1997-09-16 09:00:00';
|
92
|
$result = implode(', ', $dates);
|
93
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
94
|
|
95
|
// Weekly until September 24, 1997
|
96
|
$start = "1997-09-02 09:00:00";
|
97
|
$end = "1997-09-30 09:00:00";
|
98
|
$rule = "RRULE:FREQ=WEEKLY;UNTIL=19970924T000000Z";
|
99
|
// ==> (1997 9:00 AM EDT)September 2,9,16,23
|
100
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
101
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-09 09:00:00, 1997-09-16 09:00:00, 1997-09-23 09:00:00';
|
102
|
$result = implode(', ', $dates);
|
103
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
104
|
|
105
|
// Every other week - forever:
|
106
|
$start = "1997-09-02 09:00:00";
|
107
|
$end = "1997-09-30 09:00:00";
|
108
|
$rule = "RRULE:FREQ=WEEKLY;INTERVAL=2;WKST=SU";
|
109
|
// should be (1997 9:00 AM EDT)September 2,16,30
|
110
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
111
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-16 09:00:00, 1997-09-30 09:00:00';
|
112
|
$result = implode(', ', $dates);
|
113
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
114
|
|
115
|
// Weekly on Tuesday and Thursday for 4 weeks:
|
116
|
$start = "1997-09-02 09:00:00";
|
117
|
$end = "1997-09-30 09:00:00";
|
118
|
$rule = "RRULE:FREQ=WEEKLY;COUNT=8;WKST=SU;BYDAY=TU,TH";
|
119
|
// should be(1997 9:00 AM EDT)September 2,4,9,11,16,18,23,25
|
120
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
121
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-04 09:00:00, 1997-09-09 09:00:00, 1997-09-11 09:00:00, 1997-09-16 09:00:00, 1997-09-18 09:00:00, 1997-09-23 09:00:00, 1997-09-25 09:00:00';
|
122
|
$result = implode(', ', $dates);
|
123
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
124
|
|
125
|
// Every other week on Tuesday and Thursday, for 5 occurrences:
|
126
|
$start = "1997-09-02 09:00:00";
|
127
|
$end = "1997-09-30 09:00:00";
|
128
|
$rule = "RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=5;WKST=SU;BYDAY=TU,TH";
|
129
|
// should be (1997 9:00 AM EDT)September 2,4,16,18,30
|
130
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
131
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-04 09:00:00, 1997-09-16 09:00:00, 1997-09-18 09:00:00, 1997-09-30 09:00:00';
|
132
|
$result = implode(', ', $dates);
|
133
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
134
|
|
135
|
// Every other week on Monday, Wednesday and Friday until September 24, 1997,
|
136
|
$start = "1997-09-02 09:00:00";
|
137
|
$end = "1997-09-30 09:00:00";
|
138
|
$rule = "RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19970924T000000Z;WKST=SU;BYDAY=MO,WE,FR";
|
139
|
// should be (1997 9:00 AM EDT)September 2,3,5,15,17,19
|
140
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
141
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-03 09:00:00, 1997-09-05 09:00:00, 1997-09-15 09:00:00, 1997-09-17 09:00:00, 1997-09-19 09:00:00';
|
142
|
$result = implode(', ', $dates);
|
143
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
144
|
|
145
|
// Monthly on the 1st Friday for 2 occurrences:
|
146
|
$start = "1997-09-05 09:00:00";
|
147
|
$end = "1997-10-31 09:00:00";
|
148
|
$rule = "RRULE:FREQ=MONTHLY;COUNT=2;BYDAY=1FR";
|
149
|
// should be (1997 9:00 AM EDT)September 5;October 3
|
150
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
151
|
$shouldbe = '1997-09-05 09:00:00, 1997-10-03 09:00:00';
|
152
|
$result = implode(', ', $dates);
|
153
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
154
|
|
155
|
// Monthly on the 1st Friday until December 24, 1997:
|
156
|
$start = "1997-09-05 09:00:00";
|
157
|
$end = "1998-10-01 09:00:00";
|
158
|
$rule = "RRULE:FREQ=MONTHLY;UNTIL=19971224T000000Z;BYDAY=1FR";
|
159
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
160
|
$shouldbe = '1997-09-05 09:00:00, 1997-10-03 09:00:00, 1997-11-07 09:00:00, 1997-12-05 09:00:00';
|
161
|
$result = implode(', ', $dates);
|
162
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
163
|
|
164
|
// Every other month on the 1st and last Sunday of the month for 10 occurrences:
|
165
|
$start = "1997-09-07 09:00:00";
|
166
|
$end = "1998-10-01 09:00:00";
|
167
|
$rule = "RRULE:FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU";
|
168
|
// ==> (1997 9:00 AM EDT)September 7,28
|
169
|
// (1997 9:00 AM EST)November 2,30
|
170
|
// (1998 9:00 AM EST)January 4,25;March 1,29
|
171
|
// (1998 9:00 AM EDT)May 3,31
|
172
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
173
|
$shouldbe = '1997-09-07 09:00:00, 1997-09-28 09:00:00, 1997-11-02 09:00:00, 1997-11-30 09:00:00, 1998-01-04 09:00:00, 1998-01-25 09:00:00, 1998-03-01 09:00:00, 1998-03-29 09:00:00, 1998-05-03 09:00:00, 1998-05-31 09:00:00';
|
174
|
$result = implode(', ', $dates);
|
175
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
176
|
|
177
|
// Monthly on the second to last Monday of the month for 6 months:
|
178
|
$start = "1997-09-22 09:00:00";
|
179
|
$end = "1998-10-01 09:00:00";
|
180
|
$rule = "RRULE:FREQ=MONTHLY;COUNT=6;BYDAY=-2MO";
|
181
|
// ==> (1997 9:00 AM EDT)September 22;October 20
|
182
|
// (1997 9:00 AM EST)November 17;December 22
|
183
|
// (1998 9:00 AM EST)January 19;February 16
|
184
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
185
|
$shouldbe = '1997-09-22 09:00:00, 1997-10-20 09:00:00, 1997-11-17 09:00:00, 1997-12-22 09:00:00, 1998-01-19 09:00:00, 1998-02-16 09:00:00';
|
186
|
$result = implode(', ', $dates);
|
187
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
188
|
|
189
|
// Every Tuesday, every other month:
|
190
|
$start = "1997-09-02 09:00:00";
|
191
|
$end = "1998-02-01 09:00:00";
|
192
|
$rule = "RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=TU";
|
193
|
// ==> (1997 9:00 AM EDT)September 2,9,16,23,30
|
194
|
// (1997 9:00 AM EST)November 4,11,18,25
|
195
|
// (1998 9:00 AM EST)January 6,13,20,27;March 3,10,17,24,31
|
196
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
197
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-09 09:00:00, 1997-09-16 09:00:00, 1997-09-23 09:00:00, 1997-09-30 09:00:00, 1997-11-04 09:00:00, 1997-11-11 09:00:00, 1997-11-18 09:00:00, 1997-11-25 09:00:00, 1998-01-06 09:00:00, 1998-01-13 09:00:00, 1998-01-20 09:00:00, 1998-01-27 09:00:00';
|
198
|
$result = implode(', ', $dates);
|
199
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
200
|
|
201
|
// Yearly in June and July for 10 occurrences:
|
202
|
$start = "1997-06-10 09:00:00";
|
203
|
$end = "2002-01-01 09:00:00";
|
204
|
$rule = "RRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7";
|
205
|
// ==> (1997 9:00 AM EDT)June 10;July 10
|
206
|
// (1998 9:00 AM EDT)June 10;July 10
|
207
|
// (1999 9:00 AM EDT)June 10;July 10
|
208
|
// (2000 9:00 AM EDT)June 10;July 10
|
209
|
// (2001 9:00 AM EDT)June 10;July 10
|
210
|
// Note: Since none of the BYDAY, BYMONTHDAY or BYYEARDAY components
|
211
|
// are specified, the day is gotten from DTSTART.
|
212
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
213
|
$shouldbe = '1997-06-10 09:00:00, 1997-07-10 09:00:00, 1998-06-10 09:00:00, 1998-07-10 09:00:00, 1999-06-10 09:00:00, 1999-07-10 09:00:00, 2000-06-10 09:00:00, 2000-07-10 09:00:00, 2001-06-10 09:00:00, 2001-07-10 09:00:00';
|
214
|
$result = implode(', ', $dates);
|
215
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
216
|
|
217
|
// Every other year on January, February, and March for 10 occurrences:
|
218
|
$start = "1997-03-10 09:00:00";
|
219
|
$end = "2004-01-01 09:00:00";
|
220
|
$rule = "RRULE:FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3";
|
221
|
// ==> (1997 9:00 AM EST)March 10
|
222
|
// (1999 9:00 AM EST)January 10;February 10;March 10
|
223
|
// (2001 9:00 AM EST)January 10;February 10;March 10
|
224
|
// (2003 9:00 AM EST)January 10;February 10;March 10
|
225
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
226
|
$shouldbe = '1997-03-10 09:00:00, 1999-01-10 09:00:00, 1999-02-10 09:00:00, 1999-03-10 09:00:00, 2001-01-10 09:00:00, 2001-02-10 09:00:00, 2001-03-10 09:00:00, 2003-01-10 09:00:00, 2003-02-10 09:00:00, 2003-03-10 09:00:00';
|
227
|
$result = implode(', ', $dates);
|
228
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
229
|
|
230
|
// An example where the days generated makes a difference because of WKST:
|
231
|
$start = "1997-08-05 09:00:00";
|
232
|
$end = "2004-01-01 09:00:00";
|
233
|
$rule = "RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=MO";
|
234
|
// ==> (1997 EDT)Aug 5,10,19,24
|
235
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
236
|
$shouldbe = '1997-08-05 09:00:00, 1997-08-10 09:00:00, 1997-08-19 09:00:00, 1997-08-24 09:00:00';
|
237
|
$result = implode(', ', $dates);
|
238
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
239
|
|
240
|
// changing only WKST from MO to SU, yields different results...
|
241
|
$start = "1997-08-05 09:00:00";
|
242
|
$end = "2004-01-01 09:00:00";
|
243
|
$rule = "RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU";
|
244
|
// Result: 1997 EDT August 5,17,19,31;
|
245
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
246
|
$shouldbe = '1997-08-05 09:00:00, 1997-08-17 09:00:00, 1997-08-19 09:00:00, 1997-08-31 09:00:00';
|
247
|
$result = implode(', ', $dates);
|
248
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
249
|
|
250
|
// Every 18 months on the 10th thru 15th of the month for 10 occurrences:
|
251
|
$start = "1997-09-10 09:00:00";
|
252
|
$end = "2004-01-01 09:00:00";
|
253
|
$rule = "RRULE:FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,15";
|
254
|
// ==> (1997 9:00 AM EDT)September 10,11,12,13,14,15
|
255
|
// (1999 9:00 AM EST)March 10,11,12,13
|
256
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
257
|
$shouldbe = '1997-09-10 09:00:00, 1997-09-11 09:00:00, 1997-09-12 09:00:00, 1997-09-13 09:00:00, 1997-09-14 09:00:00, 1997-09-15 09:00:00, 1999-03-10 09:00:00, 1999-03-11 09:00:00, 1999-03-12 09:00:00, 1999-03-13 09:00:00';
|
258
|
$result = implode(', ', $dates);
|
259
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
260
|
|
261
|
// Monthly on the third to the last day of the month, forever:
|
262
|
$start = "1997-09-28 09:00:00";
|
263
|
$end = "1998-03-01 09:00:00";
|
264
|
$rule = "RRULE:FREQ=MONTHLY;BYMONTHDAY=-3";
|
265
|
// ==> (1997 9:00 AM EDT)September 28
|
266
|
// (1997 9:00 AM EST)October 29;November 28;December 29
|
267
|
// (1998 9:00 AM EST)January 29;February 26
|
268
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
269
|
$shouldbe = '1997-09-28 09:00:00, 1997-10-29 09:00:00, 1997-11-28 09:00:00, 1997-12-29 09:00:00, 1998-01-29 09:00:00, 1998-02-26 09:00:00';
|
270
|
$result = implode(', ', $dates);
|
271
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
272
|
|
273
|
// Every Thursday in March, forever:
|
274
|
// ==> (1997 9:00 AM EST)March 13,20,27
|
275
|
// (1998 9:00 AM EST)March 5,12,19,26
|
276
|
// (1999 9:00 AM EST)March 4,11,18,25
|
277
|
$start = "1997-03-13 09:00:00";
|
278
|
$end = "1999-03-31 09:00:00";
|
279
|
$rule = "RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=TH";
|
280
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
281
|
$shouldbe = '1997-03-13 09:00:00, 1997-03-20 09:00:00, 1997-03-27 09:00:00, 1998-03-05 09:00:00, 1998-03-12 09:00:00, 1998-03-19 09:00:00, 1998-03-26 09:00:00, 1999-03-04 09:00:00, 1999-03-11 09:00:00, 1999-03-18 09:00:00, 1999-03-25 09:00:00';
|
282
|
$result = implode(', ', $dates);
|
283
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
284
|
|
285
|
// Every Thursday, but only during June, July, and August, forever:
|
286
|
// ==> (1997 9:00 AM EDT)June 5,12,19,26;July 3,10,17,24,31;August 7,14,21,28
|
287
|
// (1998 9:00 AM EDT)June 4,11,18,25;July 2,9,16,23,30;August 6,13,20,27
|
288
|
// (1999 9:00 AM EDT)June 3,10,17,24;July 1,8,15,22,29;August 5,12,19,26
|
289
|
$start = "1997-06-05 09:00:00";
|
290
|
$end = "1999-08-31 09:00:00";
|
291
|
$rule = "RRULE:FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8";
|
292
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
293
|
$shouldbe = '1997-06-05 09:00:00, 1997-06-12 09:00:00, 1997-06-19 09:00:00, 1997-06-26 09:00:00, 1997-07-03 09:00:00, 1997-07-10 09:00:00, 1997-07-17 09:00:00, 1997-07-24 09:00:00, 1997-07-31 09:00:00, 1997-08-07 09:00:00, 1997-08-14 09:00:00, 1997-08-21 09:00:00, 1997-08-28 09:00:00, 1998-06-04 09:00:00, 1998-06-11 09:00:00, 1998-06-18 09:00:00, 1998-06-25 09:00:00, 1998-07-02 09:00:00, 1998-07-09 09:00:00, 1998-07-16 09:00:00, 1998-07-23 09:00:00, 1998-07-30 09:00:00, 1998-08-06 09:00:00, 1998-08-13 09:00:00, 1998-08-20 09:00:00, 1998-08-27 09:00:00, 1999-06-03 09:00:00, 1999-06-10 09:00:00, 1999-06-17 09:00:00, 1999-06-24 09:00:00, 1999-07-01 09:00:00, 1999-07-08 09:00:00, 1999-07-15 09:00:00, 1999-07-22 09:00:00, 1999-07-29 09:00:00, 1999-08-05 09:00:00, 1999-08-12 09:00:00, 1999-08-19 09:00:00, 1999-08-26 09:00:00';
|
294
|
$result = implode(', ', $dates);
|
295
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
296
|
|
297
|
// Monthly on the 2nd and 15th of the month for 10 occurrences:
|
298
|
// ==> (1997 9:00 AM EDT)September 2,15;October 2,15
|
299
|
// (1997 9:00 AM EST)November 2,15;December 2,15
|
300
|
// (1998 9:00 AM EST)January 2,15
|
301
|
$start = "1997-09-02 09:00:00";
|
302
|
$end = "1998-01-31 09:00:00";
|
303
|
$rule = "RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15";
|
304
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
305
|
$shouldbe = '1997-09-02 09:00:00, 1997-09-15 09:00:00, 1997-10-02 09:00:00, 1997-10-15 09:00:00, 1997-11-02 09:00:00, 1997-11-15 09:00:00, 1997-12-02 09:00:00, 1997-12-15 09:00:00, 1998-01-02 09:00:00, 1998-01-15 09:00:00';
|
306
|
$result = implode(', ', $dates);
|
307
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
308
|
|
309
|
// Monthly on the first and last day of the month for 10 occurrences:
|
310
|
// ==> (1997 9:00 AM EDT)September 30;October 1
|
311
|
// (1997 9:00 AM EST)October 31;November 1,30;December 1,31
|
312
|
// (1998 9:00 AM EST)January 1,31;February 1
|
313
|
$start = "1997-09-30 09:00:00";
|
314
|
$end = "1998-03-31 09:00:00";
|
315
|
$rule = "RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1";
|
316
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
317
|
$shouldbe = '1997-09-30 09:00:00, 1997-10-01 09:00:00, 1997-10-31 09:00:00, 1997-11-01 09:00:00, 1997-11-30 09:00:00, 1997-12-01 09:00:00, 1997-12-31 09:00:00, 1998-01-01 09:00:00, 1998-01-31 09:00:00, 1998-02-01 09:00:00';
|
318
|
$result = implode(', ', $dates);
|
319
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
320
|
|
321
|
// Every Friday the 13th, forever:
|
322
|
$rule = "EXDATE;TZID=US-Eastern:19970902T090000";
|
323
|
// ==> (1998 9:00 AM EST)February 13;March 13;November 13
|
324
|
// (1999 9:00 AM EDT)August 13
|
325
|
// (2000 9:00 AM EDT)October 13
|
326
|
$start = "1997-09-02 09:00:00";
|
327
|
$end = "2000-12-31 09:00:00";
|
328
|
$rule = "RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13";
|
329
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
330
|
$shouldbe = '1997-09-02 09:00:00, 1998-02-13 09:00:00, 1998-03-13 09:00:00, 1998-11-13 09:00:00, 1999-08-13 09:00:00, 2000-10-13 09:00:00';
|
331
|
$result = implode(', ', $dates);
|
332
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
333
|
|
334
|
// The first Saturday that follows the first Sunday of the month, forever:
|
335
|
// ==> (1997 9:00 AM EDT)September 13;October 11
|
336
|
// (1997 9:00 AM EST)November 8;December 13
|
337
|
// (1998 9:00 AM EST)January 10;February 7;March 7
|
338
|
// (1998 9:00 AM EDT)April 11;May 9;June 13...
|
339
|
$start = "1997-09-13 09:00:00";
|
340
|
$end = "1998-06-30 09:00:00";
|
341
|
$rule = "RRULE:FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13";
|
342
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
343
|
$shouldbe = '1997-09-13 09:00:00, 1997-10-11 09:00:00, 1997-11-08 09:00:00, 1997-12-13 09:00:00, 1998-01-10 09:00:00, 1998-02-07 09:00:00, 1998-03-07 09:00:00, 1998-04-11 09:00:00, 1998-05-09 09:00:00, 1998-06-13 09:00:00';
|
344
|
$result = implode(', ', $dates);
|
345
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
346
|
|
347
|
// Every four years, the first Tuesday after a Monday in November,
|
348
|
// forever (U.S. Presidential Election day):
|
349
|
// ==> (1996 9:00 AM EST)November 5
|
350
|
// (2000 9:00 AM EST)November 7
|
351
|
// (2004 9:00 AM EST)November 2
|
352
|
$start = "1996-11-05 09:00:00";
|
353
|
$end = "2004-11-30 09:00:00";
|
354
|
$rule = "RRULE:FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8";
|
355
|
$shouldbe = '1996-11-05 09:00:00, 2000-11-07 09:00:00, 2004-11-02 09:00:00';
|
356
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
357
|
$result = implode(', ', $dates);
|
358
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
359
|
|
360
|
// Every 20th Monday of the year, forever:
|
361
|
$start = "1997-05-19 09:00:00";
|
362
|
$end = "2000-01-01 09:00:00";
|
363
|
$rule = "RRULE:FREQ=YEARLY;BYDAY=20MO";
|
364
|
// ==> (1997 9:00 AM EDT)May 19
|
365
|
// (1998 9:00 AM EDT)May 18
|
366
|
// (1999 9:00 AM EDT)May 17
|
367
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
368
|
$shouldbe = '1997-05-19 09:00:00, 1998-05-18 09:00:00, 1999-05-17 09:00:00';
|
369
|
$result = implode(', ', $dates);
|
370
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
371
|
|
372
|
// Every Sunday in January, every other year, forever:
|
373
|
$start = "1997-01-05 09:00:00";
|
374
|
$end = "2001-02-01 09:00:00";
|
375
|
$rule = 'RRULE:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU';
|
376
|
// ==> (1997 9:00 AM EDT)January 5,12,19,26
|
377
|
// (1999 9:00 AM EDT)January 3,10,17,24,31
|
378
|
// (2001 9:00 AM EDT)January 7,14,21,28
|
379
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
380
|
$shouldbe = '1997-01-05 09:00:00, 1997-01-12 09:00:00, 1997-01-19 09:00:00, 1997-01-26 09:00:00, 1999-01-03 09:00:00, 1999-01-10 09:00:00, 1999-01-17 09:00:00, 1999-01-24 09:00:00, 1999-01-31 09:00:00, 2001-01-07 09:00:00, 2001-01-14 09:00:00, 2001-01-21 09:00:00, 2001-01-28 09:00:00';
|
381
|
$result = implode(', ', $dates);
|
382
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
383
|
|
384
|
// Every Last Thursday in November, every year, five times:
|
385
|
$start = "2014-11-27 00:00:00";
|
386
|
$rule = 'FREQ=YEARLY;INTERVAL=1;BYDAY=-1TH;BYMONTH=11;COUNT=5;WKST=SU';
|
387
|
// ==> (2014 00:00 AM EDT)November 27
|
388
|
// (2015 00:00 AM EDT)November 26
|
389
|
// (2016 00:00 AM EDT)November 24
|
390
|
// (2017 00:00 AM EDT)November 30
|
391
|
// (2018 00:00 AM EDT)November 29
|
392
|
$dates = date_repeat_calc($rule, $start, NULL, array());
|
393
|
$shouldbe = '2014-11-27 00:00:00, 2015-11-26 00:00:00, 2016-11-24 00:00:00, 2017-11-30 00:00:00, 2018-11-29 00:00:00';
|
394
|
$result = implode(', ', $dates);
|
395
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
396
|
|
397
|
return;
|
398
|
|
399
|
// Every Thanksgiving, forever:
|
400
|
$start = "1997-01-01 09:00:00";
|
401
|
$end = "2001-02-01 09:00:00";
|
402
|
$rule = 'RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=11;BYDAY=4TH';
|
403
|
// ==> (1997 9:00 AM EDT)Nov
|
404
|
// (1999 9:00 AM EDT)Nov
|
405
|
// (2001 9:00 AM EDT)Nov
|
406
|
$dates = date_repeat_calc($rule, $start, $end, array());
|
407
|
$shouldbe = '';
|
408
|
$result = implode(', ', $dates);
|
409
|
$this->assertEqual($result, $shouldbe, $rule . '; Starting ' . $start . '; results: ' . $result);
|
410
|
|
411
|
// TODO:
|
412
|
// BYYEARDAY, BYSETPOS,
|
413
|
// BYHOUR, BYMINUTE, HOURLY, MINUTELY, SECONDLY
|
414
|
// have not yet been implemented in date_repeat.
|
415
|
// Every 3rd year on the 1st, 100th and 200th day for 10 occurrences:
|
416
|
$date = "DTSTART;TZID=US-Eastern:19970101T090000";
|
417
|
$rule = "RRULE:FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200";
|
418
|
// ==> (1997 9:00 AM EST)January 1
|
419
|
// (1997 9:00 AM EDT)April 10;July 19
|
420
|
// (2000 9:00 AM EST)January 1
|
421
|
// (2000 9:00 AM EDT)April 9;July 18
|
422
|
// (2003 9:00 AM EST)January 1
|
423
|
// (2003 9:00 AM EDT)April 10;July 19
|
424
|
// (2006 9:00 AM EST)January 1
|
425
|
// Monday of week number 20 (where the default start of the week is Monday), forever:
|
426
|
$date = "DTSTART;TZID=US-Eastern:19970512T090000";
|
427
|
$rule = "RRULE:FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO";
|
428
|
// ==> (1997 9:00 AM EDT)May 12
|
429
|
// (1998 9:00 AM EDT)May 11
|
430
|
// (1999 9:00 AM EDT)May 17
|
431
|
// The 3rd instance into the month of one of Tuesday, Wednesday or
|
432
|
// Thursday, for the next 3 months:
|
433
|
$date = "DTSTART;TZID=US-Eastern:19970904T090000";
|
434
|
$rule = "RRULE:FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3";
|
435
|
// ==> (1997 9:00 AM EDT)September 4;October 7
|
436
|
// (1997 9:00 AM EST)November 6
|
437
|
// The 2nd to last weekday of the month:
|
438
|
$date = "DTSTART;TZID=US-Eastern:19970929T090000";
|
439
|
$rule = "RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2";
|
440
|
// ==> (1997 9:00 AM EDT)September 29
|
441
|
// (1997 9:00 AM EST)October 30;November 27;December 30
|
442
|
// (1998 9:00 AM EST)January 29;February 26;March 30
|
443
|
// Every 3 hours from 9:00 AM to 5:00 PM on a specific day:
|
444
|
$date = "DTSTART;TZID=US-Eastern:19970902T090000";
|
445
|
$rule = "RRULE:FREQ=HOURLY;INTERVAL=3;UNTIL=19970902T170000Z";
|
446
|
// ==> (September 2, 1997 EDT)09:00,12:00,15:00
|
447
|
// Every 15 minutes for 6 occurrences:
|
448
|
$date = "DTSTART;TZID=US-Eastern:19970902T090000";
|
449
|
$rule = "RRULE:FREQ=MINUTELY;INTERVAL=15;COUNT=6";
|
450
|
// ==> (September 2, 1997 EDT)09:00,09:15,09:30,09:45,10:00,10:15
|
451
|
// Every hour and a half for 4 occurrences:
|
452
|
$date = "DTSTART;TZID=US-Eastern:19970902T090000";
|
453
|
$rule = "RRULE:FREQ=MINUTELY;INTERVAL=90;COUNT=4";
|
454
|
// ==> (September 2, 1997 EDT)09:00,10:30;12:00;13:30
|
455
|
// Every 20 minutes from 9:00 AM to 4:40 PM every day:
|
456
|
$date = "DTSTART;TZID=US-Eastern:19970902T090000";
|
457
|
$rule = "RRULE:FREQ=DAILY;BYHOUR=9,10,11,12,13,14,15,16;BYMINUTE=0,20,40";
|
458
|
// or.
|
459
|
$rule = "RRULE:FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16";
|
460
|
// ==> (September 2, 1997 EDT)9:00,9:20,9:40,10:00,10:20,16:00,16:20,16:40
|
461
|
// (September 3, 1997 EDT)9:00,9:20,9:40,10:00,10:20,16:00,16:20,16:40
|
462
|
}
|
463
|
|
464
|
}
|