Debian Codegraph @

src/tests/rfc_tests.rs

raw symbols SCIP
1 //! This file contains examples from:
2 //! <https://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html>
3
4 use crate::tests::common;
5 use crate::RRuleSet;
6
7 // ------------------------------------------ Daily ---------------------------------------------
8
9 /// Daily for 10 occurrences
10 #[test]
11 fn daily_10_occurrences() {
12 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
13 RRULE:FREQ=DAILY;COUNT=10"
14 .parse::<RRuleSet>()
15 .unwrap()
16 .all(u16::MAX)
17 .dates;
18 common::check_occurrences(
19 &dates,
20 &[
21 "1997-09-02T09:00:00-04:00",
22 "1997-09-03T09:00:00-04:00",
23 "1997-09-04T09:00:00-04:00",
24 "1997-09-05T09:00:00-04:00",
25 "1997-09-06T09:00:00-04:00",
26 "1997-09-07T09:00:00-04:00",
27 "1997-09-08T09:00:00-04:00",
28 "1997-09-09T09:00:00-04:00",
29 "1997-09-10T09:00:00-04:00",
30 "1997-09-11T09:00:00-04:00",
31 ],
32 );
33 }
34
35 /// Daily until November 03, 1997
36 #[test]
37 fn daily_until_november() {
38 // This has been changes to make it shorter, so it is not too long.
39 // From september-november
40 let dates = "DTSTART;TZID=America/New_York:19970920T090000\n\
41 RRULE:FREQ=DAILY;UNTIL=19971103T000000Z"
42 .parse::<RRuleSet>()
43 .unwrap()
44 .all(u16::MAX)
45 .dates;
46 common::check_occurrences(
47 &dates,
48 &[
49 // September
50 "1997-09-20T09:00:00-04:00",
51 "1997-09-21T09:00:00-04:00",
52 "1997-09-22T09:00:00-04:00",
53 "1997-09-23T09:00:00-04:00",
54 "1997-09-24T09:00:00-04:00",
55 "1997-09-25T09:00:00-04:00",
56 "1997-09-26T09:00:00-04:00",
57 "1997-09-27T09:00:00-04:00",
58 "1997-09-28T09:00:00-04:00",
59 "1997-09-29T09:00:00-04:00",
60 "1997-09-30T09:00:00-04:00",
61 // October
62 "1997-10-01T09:00:00-04:00",
63 "1997-10-02T09:00:00-04:00",
64 "1997-10-03T09:00:00-04:00",
65 "1997-10-04T09:00:00-04:00",
66 "1997-10-05T09:00:00-04:00",
67 "1997-10-06T09:00:00-04:00",
68 "1997-10-07T09:00:00-04:00",
69 "1997-10-08T09:00:00-04:00",
70 "1997-10-09T09:00:00-04:00",
71 "1997-10-10T09:00:00-04:00",
72 "1997-10-11T09:00:00-04:00",
73 "1997-10-12T09:00:00-04:00",
74 "1997-10-13T09:00:00-04:00",
75 "1997-10-14T09:00:00-04:00",
76 "1997-10-15T09:00:00-04:00",
77 "1997-10-16T09:00:00-04:00",
78 "1997-10-17T09:00:00-04:00",
79 "1997-10-18T09:00:00-04:00",
80 "1997-10-19T09:00:00-04:00",
81 "1997-10-20T09:00:00-04:00",
82 "1997-10-21T09:00:00-04:00",
83 "1997-10-22T09:00:00-04:00",
84 "1997-10-23T09:00:00-04:00",
85 "1997-10-24T09:00:00-04:00",
86 "1997-10-25T09:00:00-04:00",
87 // Daylight saving time change
88 "1997-10-26T09:00:00-05:00",
89 "1997-10-27T09:00:00-05:00",
90 "1997-10-28T09:00:00-05:00",
91 "1997-10-29T09:00:00-05:00",
92 "1997-10-30T09:00:00-05:00",
93 "1997-10-31T09:00:00-05:00",
94 // November
95 "1997-11-01T09:00:00-05:00",
96 "1997-11-02T09:00:00-05:00",
97 ],
98 );
99 }
100
101 /// Every other day - forever
102 #[test]
103 fn every_other_day() {
104 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
105 RRULE:FREQ=DAILY;INTERVAL=2"
106 .parse::<RRuleSet>()
107 .unwrap()
108 .all(32)
109 .dates;
110 common::check_occurrences(
111 &dates,
112 &[
113 "1997-09-02T09:00:00-04:00",
114 "1997-09-04T09:00:00-04:00",
115 "1997-09-06T09:00:00-04:00",
116 "1997-09-08T09:00:00-04:00",
117 "1997-09-10T09:00:00-04:00",
118 "1997-09-12T09:00:00-04:00",
119 "1997-09-14T09:00:00-04:00",
120 "1997-09-16T09:00:00-04:00",
121 "1997-09-18T09:00:00-04:00",
122 "1997-09-20T09:00:00-04:00",
123 "1997-09-22T09:00:00-04:00",
124 "1997-09-24T09:00:00-04:00",
125 "1997-09-26T09:00:00-04:00",
126 "1997-09-28T09:00:00-04:00",
127 "1997-09-30T09:00:00-04:00",
128 "1997-10-02T09:00:00-04:00",
129 "1997-10-04T09:00:00-04:00",
130 "1997-10-06T09:00:00-04:00",
131 "1997-10-08T09:00:00-04:00",
132 "1997-10-10T09:00:00-04:00",
133 "1997-10-12T09:00:00-04:00",
134 "1997-10-14T09:00:00-04:00",
135 "1997-10-16T09:00:00-04:00",
136 "1997-10-18T09:00:00-04:00",
137 "1997-10-20T09:00:00-04:00",
138 "1997-10-22T09:00:00-04:00",
139 "1997-10-24T09:00:00-04:00",
140 "1997-10-26T09:00:00-05:00",
141 "1997-10-28T09:00:00-05:00",
142 "1997-10-30T09:00:00-05:00",
143 "1997-11-01T09:00:00-05:00",
144 "1997-11-03T09:00:00-05:00",
145 ],
146 );
147 }
148
149 /// Every 10 days, 5 occurrences
150 #[test]
151 fn every_10_days_5_occurrences() {
152 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
153 RRULE:FREQ=DAILY;INTERVAL=10;COUNT=5"
154 .parse::<RRuleSet>()
155 .unwrap()
156 .all(u16::MAX)
157 .dates;
158 common::check_occurrences(
159 &dates,
160 &[
161 "1997-09-02T09:00:00-04:00",
162 "1997-09-12T09:00:00-04:00",
163 "1997-09-22T09:00:00-04:00",
164 "1997-10-02T09:00:00-04:00",
165 "1997-10-12T09:00:00-04:00",
166 ],
167 );
168 }
169
170 /// Every day in January, for 3 years
171 #[test]
172 fn every_days_in_jan_for_3_years() {
173 // To patterns that have the same result
174 let dates = "DTSTART;TZID=America/New_York:19980101T090000\n\
175 RRULE:FREQ=YEARLY;UNTIL=20000131T140000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA"
176 .parse::<RRuleSet>()
177 .unwrap()
178 .all(100)
179 .dates;
180 let dates_alt = "DTSTART;TZID=America/New_York:19980101T090000\n\
181 RRULE:FREQ=DAILY;UNTIL=20000131T140000Z;BYMONTH=1"
182 .parse::<RRuleSet>()
183 .unwrap()
184 .all(100)
185 .dates;
186 let mut expected = vec![];
187 for year in 1998..=2000 {
188 for day in 1..=31 {
189 expected.push(format!("{}-01-{:02}T09:00:00-05:00", year, day));
190 }
191 }
192 common::check_occurrences(&dates, &expected);
193 common::check_occurrences(&dates_alt, &expected);
194 }
195
196 // ------------------------------------------ Weekly ---------------------------------------------
197
198 /// Weekly for 10 occurrences
199 #[test]
200 fn weekly_10_occurrences() {
201 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
202 RRULE:FREQ=WEEKLY;COUNT=10"
203 .parse::<RRuleSet>()
204 .unwrap()
205 .all(u16::MAX)
206 .dates;
207 common::check_occurrences(
208 &dates,
209 &[
210 "1997-09-02T09:00:00-04:00",
211 "1997-09-09T09:00:00-04:00",
212 "1997-09-16T09:00:00-04:00",
213 "1997-09-23T09:00:00-04:00",
214 "1997-09-30T09:00:00-04:00",
215 "1997-10-07T09:00:00-04:00",
216 "1997-10-14T09:00:00-04:00",
217 "1997-10-21T09:00:00-04:00",
218 "1997-10-28T09:00:00-05:00",
219 "1997-11-04T09:00:00-05:00",
220 ],
221 );
222 }
223
224 /// Weekly until November 03, 1997
225 #[test]
226 fn weekly_until_november() {
227 // This has been changes to make it shorter, so it is not too long.
228 // From september-november
229 let dates = "DTSTART;TZID=America/New_York:19970923T090000\n\
230 RRULE:FREQ=WEEKLY;UNTIL=19971105T000000Z"
231 .parse::<RRuleSet>()
232 .unwrap()
233 .all(u16::MAX)
234 .dates;
235 common::check_occurrences(
236 &dates,
237 &[
238 // September
239 "1997-09-23T09:00:00-04:00",
240 "1997-09-30T09:00:00-04:00",
241 // October
242 "1997-10-07T09:00:00-04:00",
243 "1997-10-14T09:00:00-04:00",
244 "1997-10-21T09:00:00-04:00",
245 // Daylight saving time change
246 "1997-10-28T09:00:00-05:00",
247 // November
248 "1997-11-04T09:00:00-05:00",
249 ],
250 );
251 }
252
253 /// Every other week - forever
254 #[test]
255 fn every_other_week() {
256 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
257 RRULE:FREQ=WEEKLY;INTERVAL=2;WKST=SU"
258 .parse::<RRuleSet>()
259 .unwrap()
260 .all(13)
261 .dates;
262 common::check_occurrences(
263 &dates,
264 &[
265 "1997-09-02T09:00:00-04:00",
266 "1997-09-16T09:00:00-04:00",
267 "1997-09-30T09:00:00-04:00",
268 "1997-10-14T09:00:00-04:00",
269 "1997-10-28T09:00:00-05:00",
270 "1997-11-11T09:00:00-05:00",
271 "1997-11-25T09:00:00-05:00",
272 "1997-12-09T09:00:00-05:00",
273 "1997-12-23T09:00:00-05:00",
274 "1998-01-06T09:00:00-05:00",
275 "1998-01-20T09:00:00-05:00",
276 "1998-02-03T09:00:00-05:00",
277 "1998-02-17T09:00:00-05:00",
278 ],
279 );
280 }
281
282 /// Weekly on Tuesday and Thursday for five weeks
283 #[test]
284 fn weekly_on_tue_and_thu_for_5_weeks() {
285 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
286 RRULE:FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH"
287 .parse::<RRuleSet>()
288 .unwrap()
289 .all(u16::MAX)
290 .dates;
291 let dates_alt = "DTSTART;TZID=America/New_York:19970902T090000\n\
292 RRULE:FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH"
293 .parse::<RRuleSet>()
294 .unwrap()
295 .all(u16::MAX)
296 .dates;
297 let expected = vec![
298 "1997-09-02T09:00:00-04:00",
299 "1997-09-04T09:00:00-04:00",
300 "1997-09-09T09:00:00-04:00",
301 "1997-09-11T09:00:00-04:00",
302 "1997-09-16T09:00:00-04:00",
303 "1997-09-18T09:00:00-04:00",
304 "1997-09-23T09:00:00-04:00",
305 "1997-09-25T09:00:00-04:00",
306 "1997-09-30T09:00:00-04:00",
307 "1997-10-02T09:00:00-04:00",
308 ];
309 common::check_occurrences(&dates, &expected);
310 common::check_occurrences(&dates_alt, &expected);
311 }
312
313 /// Every other week on Monday, Wednesday, and Friday until December 24, 1997,
314 /// starting on Monday, September 1, 1997
315 #[test]
316 fn every_other_week_some_days_until_dec() {
317 let dates = "DTSTART;TZID=America/New_York:19970901T090000\n\
318 RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR"
319 .parse::<RRuleSet>()
320 .unwrap()
321 .all(u16::MAX)
322 .dates;
323 common::check_occurrences(
324 &dates,
325 &[
326 "1997-09-01T09:00:00-04:00",
327 "1997-09-03T09:00:00-04:00",
328 "1997-09-05T09:00:00-04:00",
329 "1997-09-15T09:00:00-04:00",
330 "1997-09-17T09:00:00-04:00",
331 "1997-09-19T09:00:00-04:00",
332 "1997-09-29T09:00:00-04:00",
333 "1997-10-01T09:00:00-04:00",
334 "1997-10-03T09:00:00-04:00",
335 "1997-10-13T09:00:00-04:00",
336 "1997-10-15T09:00:00-04:00",
337 "1997-10-17T09:00:00-04:00",
338 "1997-10-27T09:00:00-05:00",
339 "1997-10-29T09:00:00-05:00",
340 "1997-10-31T09:00:00-05:00",
341 "1997-11-10T09:00:00-05:00",
342 "1997-11-12T09:00:00-05:00",
343 "1997-11-14T09:00:00-05:00",
344 "1997-11-24T09:00:00-05:00",
345 "1997-11-26T09:00:00-05:00",
346 "1997-11-28T09:00:00-05:00",
347 "1997-12-08T09:00:00-05:00",
348 "1997-12-10T09:00:00-05:00",
349 "1997-12-12T09:00:00-05:00",
350 "1997-12-22T09:00:00-05:00",
351 ],
352 );
353 }
354
355 /// Every other week on Tuesday and Thursday, for 8 occurrences
356 #[test]
357 fn every_other_week_some_days_8_occurrences() {
358 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
359 RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=8;WKST=SU;BYDAY=TU,TH"
360 .parse::<RRuleSet>()
361 .unwrap()
362 .all(u16::MAX)
363 .dates;
364 common::check_occurrences(
365 &dates,
366 &[
367 "1997-09-02T09:00:00-04:00",
368 "1997-09-04T09:00:00-04:00",
369 "1997-09-16T09:00:00-04:00",
370 "1997-09-18T09:00:00-04:00",
371 "1997-09-30T09:00:00-04:00",
372 "1997-10-02T09:00:00-04:00",
373 "1997-10-14T09:00:00-04:00",
374 "1997-10-16T09:00:00-04:00",
375 ],
376 );
377 }
378
379 // ------------------------------------------ Monthly ---------------------------------------------
380
381 /// Monthly on the first Friday for 10 occurrences
382 #[test]
383 fn monthly_on_first_friday_10_occurrences() {
384 let dates = "DTSTART;TZID=America/New_York:19970905T090000\n\
385 RRULE:FREQ=MONTHLY;COUNT=10;BYDAY=1FR"
386 .parse::<RRuleSet>()
387 .unwrap()
388 .all(u16::MAX)
389 .dates;
390 common::check_occurrences(
391 &dates,
392 &[
393 "1997-09-05T09:00:00-04:00",
394 "1997-10-03T09:00:00-04:00",
395 "1997-11-07T09:00:00-05:00",
396 "1997-12-05T09:00:00-05:00",
397 "1998-01-02T09:00:00-05:00",
398 "1998-02-06T09:00:00-05:00",
399 "1998-03-06T09:00:00-05:00",
400 "1998-04-03T09:00:00-05:00",
401 "1998-05-01T09:00:00-04:00",
402 "1998-06-05T09:00:00-04:00",
403 ],
404 );
405 }
406
407 /// Monthly on the first Friday until December 24, 1997
408 #[test]
409 fn monthly_on_first_friday_until_dec() {
410 let dates = "DTSTART;TZID=America/New_York:19970905T090000\n\
411 RRULE:FREQ=MONTHLY;UNTIL=19971224T000000Z;BYDAY=1FR"
412 .parse::<RRuleSet>()
413 .unwrap()
414 .all(u16::MAX)
415 .dates;
416 common::check_occurrences(
417 &dates,
418 &[
419 "1997-09-05T09:00:00-04:00",
420 "1997-10-03T09:00:00-04:00",
421 "1997-11-07T09:00:00-05:00",
422 "1997-12-05T09:00:00-05:00",
423 ],
424 );
425 }
426
427 /// Every other month on the first and last Sunday of the month for 10 occurrences
428 #[test]
429 fn every_other_month_on_first_and_last_sunday_10_occurrences() {
430 let dates = "DTSTART;TZID=America/New_York:19970907T090000\n\
431 RRULE:FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU"
432 .parse::<RRuleSet>()
433 .unwrap()
434 .all(u16::MAX)
435 .dates;
436 common::check_occurrences(
437 &dates,
438 &[
439 "1997-09-07T09:00:00-04:00",
440 "1997-09-28T09:00:00-04:00",
441 "1997-11-02T09:00:00-05:00",
442 "1997-11-30T09:00:00-05:00",
443 "1998-01-04T09:00:00-05:00",
444 "1998-01-25T09:00:00-05:00",
445 "1998-03-01T09:00:00-05:00",
446 "1998-03-29T09:00:00-05:00",
447 "1998-05-03T09:00:00-04:00",
448 "1998-05-31T09:00:00-04:00",
449 ],
450 );
451 }
452
453 /// Monthly on the second-to-last Monday of the month for 6 months
454 #[test]
455 fn monthly_on_second_to_last_monday_for_6_months() {
456 let dates = "DTSTART;TZID=America/New_York:19970922T090000\n\
457 RRULE:FREQ=MONTHLY;COUNT=6;BYDAY=-2MO"
458 .parse::<RRuleSet>()
459 .unwrap()
460 .all(u16::MAX)
461 .dates;
462 common::check_occurrences(
463 &dates,
464 &[
465 "1997-09-22T09:00:00-04:00",
466 "1997-10-20T09:00:00-04:00",
467 "1997-11-17T09:00:00-05:00",
468 "1997-12-22T09:00:00-05:00",
469 "1998-01-19T09:00:00-05:00",
470 "1998-02-16T09:00:00-05:00",
471 ],
472 );
473 }
474
475 /// Monthly on the third-to-the-last day of the month, forever
476 #[test]
477 fn monthly_on_third_to_last_day_forever() {
478 let dates = "DTSTART;TZID=America/New_York:19970928T090000\n\
479 RRULE:FREQ=MONTHLY;BYMONTHDAY=-3"
480 .parse::<RRuleSet>()
481 .unwrap()
482 .all(6)
483 .dates;
484 common::check_occurrences(
485 &dates,
486 &[
487 "1997-09-28T09:00:00-04:00",
488 "1997-10-29T09:00:00-05:00",
489 "1997-11-28T09:00:00-05:00",
490 "1997-12-29T09:00:00-05:00",
491 "1998-01-29T09:00:00-05:00",
492 "1998-02-26T09:00:00-05:00",
493 ],
494 );
495 }
496
497 /// Monthly on the 2nd and 15th of the month for 10 occurrences
498 #[test]
499 fn monthly_on_2nd_and_15th_10_occurrences() {
500 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
501 RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15"
502 .parse::<RRuleSet>()
503 .unwrap()
504 .all(u16::MAX)
505 .dates;
506 common::check_occurrences(
507 &dates,
508 &[
509 "1997-09-02T09:00:00-04:00",
510 "1997-09-15T09:00:00-04:00",
511 "1997-10-02T09:00:00-04:00",
512 "1997-10-15T09:00:00-04:00",
513 "1997-11-02T09:00:00-05:00",
514 "1997-11-15T09:00:00-05:00",
515 "1997-12-02T09:00:00-05:00",
516 "1997-12-15T09:00:00-05:00",
517 "1998-01-02T09:00:00-05:00",
518 "1998-01-15T09:00:00-05:00",
519 ],
520 );
521 }
522
523 /// Monthly on the first and last day of the month for 10 occurrences
524 #[test]
525 fn monthly_on_first_and_last_day_10_occurrences() {
526 let dates = "DTSTART;TZID=America/New_York:19970930T090000\n\
527 RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1"
528 .parse::<RRuleSet>()
529 .unwrap()
530 .all(u16::MAX)
531 .dates;
532 common::check_occurrences(
533 &dates,
534 &[
535 "1997-09-30T09:00:00-04:00",
536 "1997-10-01T09:00:00-04:00",
537 "1997-10-31T09:00:00-05:00",
538 "1997-11-01T09:00:00-05:00",
539 "1997-11-30T09:00:00-05:00",
540 "1997-12-01T09:00:00-05:00",
541 "1997-12-31T09:00:00-05:00",
542 "1998-01-01T09:00:00-05:00",
543 "1998-01-31T09:00:00-05:00",
544 "1998-02-01T09:00:00-05:00",
545 ],
546 );
547 }
548
549 /// Every 18 months on the 10th through 15th of the month for 10 occurrences
550 #[test]
551 fn every_18_months_10th_to_15th_10_occurrences() {
552 let dates = "DTSTART;TZID=America/New_York:19970910T090000\n\
553 RRULE:FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,15"
554 .parse::<RRuleSet>()
555 .unwrap()
556 .all(u16::MAX)
557 .dates;
558 common::check_occurrences(
559 &dates,
560 &[
561 "1997-09-10T09:00:00-04:00",
562 "1997-09-11T09:00:00-04:00",
563 "1997-09-12T09:00:00-04:00",
564 "1997-09-13T09:00:00-04:00",
565 "1997-09-14T09:00:00-04:00",
566 "1997-09-15T09:00:00-04:00",
567 "1999-03-10T09:00:00-05:00",
568 "1999-03-11T09:00:00-05:00",
569 "1999-03-12T09:00:00-05:00",
570 "1999-03-13T09:00:00-05:00",
571 ],
572 );
573 }
574
575 /// Every Tuesday, every other month
576 #[test]
577 fn every_tuesday_every_other_month() {
578 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
579 RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=TU"
580 .parse::<RRuleSet>()
581 .unwrap()
582 .all(18)
583 .dates;
584 common::check_occurrences(
585 &dates,
586 &[
587 "1997-09-02T09:00:00-04:00",
588 "1997-09-09T09:00:00-04:00",
589 "1997-09-16T09:00:00-04:00",
590 "1997-09-23T09:00:00-04:00",
591 "1997-09-30T09:00:00-04:00",
592 "1997-11-04T09:00:00-05:00",
593 "1997-11-11T09:00:00-05:00",
594 "1997-11-18T09:00:00-05:00",
595 "1997-11-25T09:00:00-05:00",
596 "1998-01-06T09:00:00-05:00",
597 "1998-01-13T09:00:00-05:00",
598 "1998-01-20T09:00:00-05:00",
599 "1998-01-27T09:00:00-05:00",
600 "1998-03-03T09:00:00-05:00",
601 "1998-03-10T09:00:00-05:00",
602 "1998-03-17T09:00:00-05:00",
603 "1998-03-24T09:00:00-05:00",
604 "1998-03-31T09:00:00-05:00",
605 ],
606 );
607 }
608
609 // ------------------------------------------ Yearly ---------------------------------------------
610
611 /// Yearly in June and July for 10 occurrences
612 ///
613 /// Note: Since none of the BYDAY, BYMONTHDAY, or BYYEARDAY components are specified,
614 /// the day is gotten from "DTSTART".
615 #[test]
616 fn yearly_in_june_and_july_for_10_occurrences() {
617 let dates = "DTSTART;TZID=America/New_York:19970610T090000\n\
618 RRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7"
619 .parse::<RRuleSet>()
620 .unwrap()
621 .all(u16::MAX)
622 .dates;
623 common::check_occurrences(
624 &dates,
625 &[
626 "1997-06-10T09:00:00-04:00",
627 "1997-07-10T09:00:00-04:00",
628 "1998-06-10T09:00:00-04:00",
629 "1998-07-10T09:00:00-04:00",
630 "1999-06-10T09:00:00-04:00",
631 "1999-07-10T09:00:00-04:00",
632 "2000-06-10T09:00:00-04:00",
633 "2000-07-10T09:00:00-04:00",
634 "2001-06-10T09:00:00-04:00",
635 "2001-07-10T09:00:00-04:00",
636 ],
637 );
638 }
639
640 /// Every other year on January, February, and March for 10 occurrences
641 #[test]
642 fn every_other_year_on_jan_feb_and_march_for_10_occurrences() {
643 let dates = "DTSTART;TZID=America/New_York:19970310T090000\n\
644 RRULE:FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3"
645 .parse::<RRuleSet>()
646 .unwrap()
647 .all(u16::MAX)
648 .dates;
649 common::check_occurrences(
650 &dates,
651 &[
652 "1997-03-10T09:00:00-05:00",
653 "1999-01-10T09:00:00-05:00",
654 "1999-02-10T09:00:00-05:00",
655 "1999-03-10T09:00:00-05:00",
656 "2001-01-10T09:00:00-05:00",
657 "2001-02-10T09:00:00-05:00",
658 "2001-03-10T09:00:00-05:00",
659 "2003-01-10T09:00:00-05:00",
660 "2003-02-10T09:00:00-05:00",
661 "2003-03-10T09:00:00-05:00",
662 ],
663 );
664 }
665
666 /// Every third year on the 1st, 100th, and 200th day for 10 occurrences
667 #[test]
668 fn every_third_year_on_1st_100th_and_200th_day_for_10_occurrences() {
669 let dates = "DTSTART;TZID=America/New_York:19970101T090000\n\
670 RRULE:FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200"
671 .parse::<RRuleSet>()
672 .unwrap()
673 .all(u16::MAX)
674 .dates;
675 common::check_occurrences(
676 &dates,
677 &[
678 "1997-01-01T09:00:00-05:00",
679 "1997-04-10T09:00:00-04:00",
680 "1997-07-19T09:00:00-04:00",
681 "2000-01-01T09:00:00-05:00",
682 "2000-04-09T09:00:00-04:00",
683 "2000-07-18T09:00:00-04:00",
684 "2003-01-01T09:00:00-05:00",
685 "2003-04-10T09:00:00-04:00",
686 "2003-07-19T09:00:00-04:00",
687 "2006-01-01T09:00:00-05:00",
688 ],
689 );
690 }
691
692 /// Every 20th Monday of the year, forever
693 #[test]
694 fn every_20th_monday_of_year_forever() {
695 let dates = "DTSTART;TZID=America/New_York:19970519T090000\n\
696 RRULE:FREQ=YEARLY;BYDAY=20MO"
697 .parse::<RRuleSet>()
698 .unwrap()
699 .all(3)
700 .dates;
701 common::check_occurrences(
702 &dates,
703 &[
704 "1997-05-19T09:00:00-04:00",
705 "1998-05-18T09:00:00-04:00",
706 "1999-05-17T09:00:00-04:00",
707 ],
708 );
709 }
710
711 /// Monday of week number 20 (where the default start of the week is Monday), forever
712 #[test]
713 fn monday_of_week_20_forever() {
714 let dates = "DTSTART;TZID=America/New_York:19970512T090000\n\
715 RRULE:FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO"
716 .parse::<RRuleSet>()
717 .unwrap()
718 .all(3)
719 .dates;
720 common::check_occurrences(
721 &dates,
722 &[
723 "1997-05-12T09:00:00-04:00",
724 "1998-05-11T09:00:00-04:00",
725 "1999-05-17T09:00:00-04:00",
726 ],
727 );
728 }
729
730 /// Every Thursday in March, forever
731 #[test]
732 fn every_thursday_in_march_forever() {
733 let dates = "DTSTART;TZID=America/New_York:19970313T090000\n\
734 RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=TH"
735 .parse::<RRuleSet>()
736 .unwrap()
737 .all(11)
738 .dates;
739 common::check_occurrences(
740 &dates,
741 &[
742 "1997-03-13T09:00:00-05:00",
743 "1997-03-20T09:00:00-05:00",
744 "1997-03-27T09:00:00-05:00",
745 "1998-03-05T09:00:00-05:00",
746 "1998-03-12T09:00:00-05:00",
747 "1998-03-19T09:00:00-05:00",
748 "1998-03-26T09:00:00-05:00",
749 "1999-03-04T09:00:00-05:00",
750 "1999-03-11T09:00:00-05:00",
751 "1999-03-18T09:00:00-05:00",
752 "1999-03-25T09:00:00-05:00",
753 ],
754 );
755 }
756
757 /// Every Thursday, but only during June, July, and August, forever
758 #[test]
759 fn every_thursday_only_during_june_july_and_august_forever() {
760 let dates = "DTSTART;TZID=America/New_York:19970605T090000\n\
761 RRULE:FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8"
762 .parse::<RRuleSet>()
763 .unwrap()
764 .all(39)
765 .dates;
766 common::check_occurrences(
767 &dates,
768 &[
769 "1997-06-05T09:00:00-04:00",
770 "1997-06-12T09:00:00-04:00",
771 "1997-06-19T09:00:00-04:00",
772 "1997-06-26T09:00:00-04:00",
773 "1997-07-03T09:00:00-04:00",
774 "1997-07-10T09:00:00-04:00",
775 "1997-07-17T09:00:00-04:00",
776 "1997-07-24T09:00:00-04:00",
777 "1997-07-31T09:00:00-04:00",
778 "1997-08-07T09:00:00-04:00",
779 "1997-08-14T09:00:00-04:00",
780 "1997-08-21T09:00:00-04:00",
781 "1997-08-28T09:00:00-04:00",
782 "1998-06-04T09:00:00-04:00",
783 "1998-06-11T09:00:00-04:00",
784 "1998-06-18T09:00:00-04:00",
785 "1998-06-25T09:00:00-04:00",
786 "1998-07-02T09:00:00-04:00",
787 "1998-07-09T09:00:00-04:00",
788 "1998-07-16T09:00:00-04:00",
789 "1998-07-23T09:00:00-04:00",
790 "1998-07-30T09:00:00-04:00",
791 "1998-08-06T09:00:00-04:00",
792 "1998-08-13T09:00:00-04:00",
793 "1998-08-20T09:00:00-04:00",
794 "1998-08-27T09:00:00-04:00",
795 "1999-06-03T09:00:00-04:00",
796 "1999-06-10T09:00:00-04:00",
797 "1999-06-17T09:00:00-04:00",
798 "1999-06-24T09:00:00-04:00",
799 "1999-07-01T09:00:00-04:00",
800 "1999-07-08T09:00:00-04:00",
801 "1999-07-15T09:00:00-04:00",
802 "1999-07-22T09:00:00-04:00",
803 "1999-07-29T09:00:00-04:00",
804 "1999-08-05T09:00:00-04:00",
805 "1999-08-12T09:00:00-04:00",
806 "1999-08-19T09:00:00-04:00",
807 "1999-08-26T09:00:00-04:00",
808 ],
809 );
810 }
811
812 /// Every Friday the 13th, forever
813 #[test]
814 fn every_friday_the_13th_forever() {
815 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
816 EXDATE;TZID=America/New_York:19970902T090000\n\
817 RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13"
818 .parse::<RRuleSet>()
819 .unwrap()
820 .all(5)
821 .dates;
822 common::check_occurrences(
823 &dates,
824 &[
825 "1998-02-13T09:00:00-05:00",
826 "1998-03-13T09:00:00-05:00",
827 "1998-11-13T09:00:00-05:00",
828 "1999-08-13T09:00:00-04:00",
829 "2000-10-13T09:00:00-04:00",
830 ],
831 );
832 }
833
834 /// The first Saturday that follows the first Sunday of the month forever
835 #[test]
836 fn first_sat_follows_first_sunday_of_month_forever() {
837 let dates = "DTSTART;TZID=America/New_York:19970913T090000\n\
838 RRULE:FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13"
839 .parse::<RRuleSet>()
840 .unwrap()
841 .all(10)
842 .dates;
843 common::check_occurrences(
844 &dates,
845 &[
846 "1997-09-13T09:00:00-04:00",
847 "1997-10-11T09:00:00-04:00",
848 "1997-11-08T09:00:00-05:00",
849 "1997-12-13T09:00:00-05:00",
850 "1998-01-10T09:00:00-05:00",
851 "1998-02-07T09:00:00-05:00",
852 "1998-03-07T09:00:00-05:00",
853 "1998-04-11T09:00:00-04:00",
854 "1998-05-09T09:00:00-04:00",
855 "1998-06-13T09:00:00-04:00",
856 ],
857 );
858 }
859
860 /// Every 4 years, the first Tuesday after a Monday in November, forever
861 /// (U.S. Presidential Election day)
862 #[test]
863 fn every_4_years_us_presidential_election_day_forever() {
864 let dates = "DTSTART;TZID=America/New_York:19961105T090000\n\
865 RRULE:FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8"
866 .parse::<RRuleSet>()
867 .unwrap()
868 .all(3)
869 .dates;
870 common::check_occurrences(
871 &dates,
872 &[
873 "1996-11-05T09:00:00-05:00",
874 "2000-11-07T09:00:00-05:00",
875 "2004-11-02T09:00:00-05:00",
876 ],
877 );
878 }
879
880 /// The third instance into the month of one of Tuesday, Wednesday, or Thursday,
881 /// for the next 3 months
882 #[test]
883 fn every_third_instance_of_weekday_in_month_for_3_months() {
884 let dates = "DTSTART;TZID=America/New_York:19970904T090000\n\
885 RRULE:FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3"
886 .parse::<RRuleSet>()
887 .unwrap()
888 .all(u16::MAX)
889 .dates;
890 common::check_occurrences(
891 &dates,
892 &[
893 "1997-09-04T09:00:00-04:00",
894 "1997-10-07T09:00:00-04:00",
895 "1997-11-06T09:00:00-05:00",
896 ],
897 );
898 }
899
900 /// The second-to-last weekday of the month
901 #[test]
902 fn second_to_last_weekday_of_month() {
903 let dates = "DTSTART;TZID=America/New_York:19970929T090000\n\
904 RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2"
905 .parse::<RRuleSet>()
906 .unwrap()
907 .all(7)
908 .dates;
909 common::check_occurrences(
910 &dates,
911 &[
912 "1997-09-29T09:00:00-04:00",
913 "1997-10-30T09:00:00-05:00",
914 "1997-11-27T09:00:00-05:00",
915 "1997-12-30T09:00:00-05:00",
916 "1998-01-29T09:00:00-05:00",
917 "1998-02-26T09:00:00-05:00",
918 "1998-03-30T09:00:00-05:00",
919 ],
920 );
921 }
922
923 /// Every 3 hours from 9:00 AM to 5:00 PM on a specific day
924 #[test]
925 fn every_3_hours_on_specific_day() {
926 // https://www.rfc-editor.org/errata/eid3883
927 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
928 RRULE:FREQ=HOURLY;INTERVAL=3;UNTIL=19970902T210000Z"
929 .parse::<RRuleSet>()
930 .unwrap()
931 .all(u16::MAX)
932 .dates;
933 common::check_occurrences(
934 &dates,
935 &[
936 "1997-09-02T09:00:00-04:00",
937 "1997-09-02T12:00:00-04:00",
938 "1997-09-02T15:00:00-04:00", // Missing from result
939 ],
940 );
941 }
942
943 /// Every 15 minutes for 6 occurrences
944 #[test]
945 fn every_15_min_for_6_occurrences() {
946 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
947 RRULE:FREQ=MINUTELY;INTERVAL=15;COUNT=6"
948 .parse::<RRuleSet>()
949 .unwrap()
950 .all(u16::MAX)
951 .dates;
952 common::check_occurrences(
953 &dates,
954 &[
955 "1997-09-02T09:00:00-04:00",
956 "1997-09-02T09:15:00-04:00",
957 "1997-09-02T09:30:00-04:00",
958 "1997-09-02T09:45:00-04:00",
959 "1997-09-02T10:00:00-04:00",
960 "1997-09-02T10:15:00-04:00",
961 ],
962 );
963 }
964
965 /// Every hour and a half for 4 occurrences
966 #[test]
967 fn every_hour_and_a_half_for_4_occurrences() {
968 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
969 RRULE:FREQ=MINUTELY;INTERVAL=90;COUNT=4"
970 .parse::<RRuleSet>()
971 .unwrap()
972 .all(u16::MAX)
973 .dates;
974 common::check_occurrences(
975 &dates,
976 &[
977 "1997-09-02T09:00:00-04:00",
978 "1997-09-02T10:30:00-04:00",
979 "1997-09-02T12:00:00-04:00",
980 "1997-09-02T13:30:00-04:00",
981 ],
982 );
983 }
984
985 /// Every 20 minutes from 9:00 AM to 4:40 PM every day
986 #[test]
987 fn every_20_min_at_time_every_day() {
988 let dates = "DTSTART;TZID=America/New_York:19970902T090000\n\
989 RRULE:FREQ=DAILY;BYHOUR=9,10,11,12,13,14,15,16;BYMINUTE=0,20,40"
990 .parse::<RRuleSet>()
991 .unwrap()
992 .all(72)
993 .dates;
994 let dates_alt = "DTSTART;TZID=America/New_York:19970902T090000\n\
995 RRULE:FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16"
996 .parse::<RRuleSet>()
997 .unwrap()
998 .all(72)
999 .dates;
1000
1001 let mut expected = vec![];
1002 for day in 2..=4 {
1003 expected.append(&mut vec![
1004 format!("1997-09-{:02}T09:00:00-04:00", day),
1005 format!("1997-09-{:02}T09:20:00-04:00", day),
1006 format!("1997-09-{:02}T09:40:00-04:00", day),
1007 format!("1997-09-{:02}T10:00:00-04:00", day),
1008 format!("1997-09-{:02}T10:20:00-04:00", day),
1009 format!("1997-09-{:02}T10:40:00-04:00", day),
1010 format!("1997-09-{:02}T11:00:00-04:00", day),
1011 format!("1997-09-{:02}T11:20:00-04:00", day),
1012 format!("1997-09-{:02}T11:40:00-04:00", day),
1013 format!("1997-09-{:02}T12:00:00-04:00", day),
1014 format!("1997-09-{:02}T12:20:00-04:00", day),
1015 format!("1997-09-{:02}T12:40:00-04:00", day),
1016 format!("1997-09-{:02}T13:00:00-04:00", day),
1017 format!("1997-09-{:02}T13:20:00-04:00", day),
1018 format!("1997-09-{:02}T13:40:00-04:00", day),
1019 format!("1997-09-{:02}T14:00:00-04:00", day),
1020 format!("1997-09-{:02}T14:20:00-04:00", day),
1021 format!("1997-09-{:02}T14:40:00-04:00", day),
1022 format!("1997-09-{:02}T15:00:00-04:00", day),
1023 format!("1997-09-{:02}T15:20:00-04:00", day),
1024 format!("1997-09-{:02}T15:40:00-04:00", day),
1025 format!("1997-09-{:02}T16:00:00-04:00", day),
1026 format!("1997-09-{:02}T16:20:00-04:00", day),
1027 format!("1997-09-{:02}T16:40:00-04:00", day),
1028 ]);
1029 }
1030 common::check_occurrences(&dates, &expected);
1031 common::check_occurrences(&dates_alt, &expected);
1032 }
1033
1034 /// An example where the days generated make a difference because of `WKST` (week start)
1035 #[test]
1036 fn week_day_start_monday_generated_days() {
1037 let dates = "DTSTART;TZID=America/New_York:19970805T090000\n\
1038 RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=MO"
1039 .parse::<RRuleSet>()
1040 .unwrap()
1041 .all(u16::MAX)
1042 .dates;
1043 common::check_occurrences(
1044 &dates,
1045 &[
1046 "1997-08-05T09:00:00-04:00",
1047 "1997-08-10T09:00:00-04:00",
1048 "1997-08-19T09:00:00-04:00",
1049 "1997-08-24T09:00:00-04:00",
1050 ],
1051 );
1052 }
1053
1054 /// Changing only WKST from MO to SU, yields different results...
1055 #[test]
1056 fn week_day_start_sunday_generated_days() {
1057 let dates = "DTSTART;TZID=America/New_York:19970805T090000\n\
1058 RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU"
1059 .parse::<RRuleSet>()
1060 .unwrap()
1061 .all(u16::MAX)
1062 .dates;
1063 common::check_occurrences(
1064 &dates,
1065 &[
1066 "1997-08-05T09:00:00-04:00",
1067 "1997-08-17T09:00:00-04:00",
1068 "1997-08-19T09:00:00-04:00",
1069 "1997-08-31T09:00:00-04:00",
1070 ],
1071 );
1072 }
1073
1074 /// An example where an invalid date (i.e., February 30) is ignored.
1075 #[test]
1076 fn invalid_date_is_ignored() {
1077 let dates = "DTSTART;TZID=America/New_York:20070115T090000\n\
1078 RRULE:FREQ=MONTHLY;BYMONTHDAY=15,30;COUNT=5"
1079 .parse::<RRuleSet>()
1080 .unwrap()
1081 .all(u16::MAX)
1082 .dates;
1083 common::check_occurrences(
1084 &dates,
1085 &[
1086 "2007-01-15T09:00:00-05:00",
1087 "2007-01-30T09:00:00-05:00",
1088 "2007-02-15T09:00:00-05:00",
1089 "2007-03-15T09:00:00-04:00",
1090 "2007-03-30T09:00:00-04:00",
1091 ],
1092 );
1093 }