• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1=====
2rrule
3=====
4
5.. automodule:: dateutil.rrule
6   :undoc-members:
7
8Classes
9-------
10
11.. autoclass:: rrule
12.. autoclass:: rruleset
13
14Functions
15---------
16
17.. autofunction:: rrulestr
18
19
20rrule examples
21--------------
22These examples were converted from the RFC.
23
24Prepare the environment.
25
26.. testsetup:: rrule
27
28    from dateutil.rrule import *
29    from dateutil.parser import *
30    from datetime import *
31    import pprint
32    import sys
33    sys.displayhook = pprint.pprint
34
35.. doctest:: rrule
36
37    >>> from dateutil.rrule import *
38    >>> from dateutil.parser import *
39    >>> from datetime import *
40
41    >>> import pprint
42    >>> import sys
43    >>> sys.displayhook = pprint.pprint
44
45Daily, for 10 occurrences.
46
47.. doctest:: rrule
48   :options: +NORMALIZE_WHITESPACE
49
50    >>> list(rrule(DAILY, count=10,
51    ...            dtstart=parse("19970902T090000")))
52    [datetime.datetime(1997, 9, 2, 9, 0),
53     datetime.datetime(1997, 9, 3, 9, 0),
54     datetime.datetime(1997, 9, 4, 9, 0),
55     datetime.datetime(1997, 9, 5, 9, 0),
56     datetime.datetime(1997, 9, 6, 9, 0),
57     datetime.datetime(1997, 9, 7, 9, 0),
58     datetime.datetime(1997, 9, 8, 9, 0),
59     datetime.datetime(1997, 9, 9, 9, 0),
60     datetime.datetime(1997, 9, 10, 9, 0),
61     datetime.datetime(1997, 9, 11, 9, 0)]
62
63Daily until December 24, 1997
64
65.. doctest:: rrule
66   :options: +NORMALIZE_WHITESPACE, +ELLIPSIS
67
68    >>> list(rrule(DAILY,
69    ...            dtstart=parse("19970902T090000"),
70    ...            until=parse("19971224T000000")))
71    [datetime.datetime(1997, 9, 2, 9, 0),
72     datetime.datetime(1997, 9, 3, 9, 0),
73     datetime.datetime(1997, 9, 4, 9, 0),
74     ...
75     datetime.datetime(1997, 12, 21, 9, 0),
76     datetime.datetime(1997, 12, 22, 9, 0),
77     datetime.datetime(1997, 12, 23, 9, 0)]
78
79Every other day, 5 occurrences.
80
81.. doctest:: rrule
82   :options: +NORMALIZE_WHITESPACE
83
84    >>> list(rrule(DAILY, interval=2, count=5,
85    ...            dtstart=parse("19970902T090000")))
86    [datetime.datetime(1997, 9, 2, 9, 0),
87     datetime.datetime(1997, 9, 4, 9, 0),
88     datetime.datetime(1997, 9, 6, 9, 0),
89     datetime.datetime(1997, 9, 8, 9, 0),
90     datetime.datetime(1997, 9, 10, 9, 0)]
91
92Every 10 days, 5 occurrences.
93
94.. doctest:: rrule
95   :options: +NORMALIZE_WHITESPACE
96
97    >>> list(rrule(DAILY, interval=10, count=5,
98    ...            dtstart=parse("19970902T090000")))
99    [datetime.datetime(1997, 9, 2, 9, 0),
100     datetime.datetime(1997, 9, 12, 9, 0),
101     datetime.datetime(1997, 9, 22, 9, 0),
102     datetime.datetime(1997, 10, 2, 9, 0),
103     datetime.datetime(1997, 10, 12, 9, 0)]
104
105Everyday in January, for 3 years.
106
107.. doctest:: rrule
108   :options: +NORMALIZE_WHITESPACE, +ELLIPSIS
109
110    >>> list(rrule(YEARLY, bymonth=1, byweekday=range(7),
111    ...            dtstart=parse("19980101T090000"),
112    ...            until=parse("20000131T090000")))
113    [datetime.datetime(1998, 1, 1, 9, 0),
114     datetime.datetime(1998, 1, 2, 9, 0),
115     ...
116     datetime.datetime(1998, 1, 30, 9, 0),
117     datetime.datetime(1998, 1, 31, 9, 0),
118     datetime.datetime(1999, 1, 1, 9, 0),
119     datetime.datetime(1999, 1, 2, 9, 0),
120     ...
121     datetime.datetime(1999, 1, 30, 9, 0),
122     datetime.datetime(1999, 1, 31, 9, 0),
123     datetime.datetime(2000, 1, 1, 9, 0),
124     datetime.datetime(2000, 1, 2, 9, 0),
125     ...
126     datetime.datetime(2000, 1, 30, 9, 0),
127     datetime.datetime(2000, 1, 31, 9, 0)]
128
129Same thing, in another way.
130
131.. doctest:: rrule
132   :options: +NORMALIZE_WHITESPACE, +ELLIPSIS
133
134    >>> list(rrule(DAILY, bymonth=1,
135    ...            dtstart=parse("19980101T090000"),
136    ...            until=parse("20000131T090000")))
137    [datetime.datetime(1998, 1, 1, 9, 0),
138     ...
139     datetime.datetime(2000, 1, 31, 9, 0)]
140
141Weekly for 10 occurrences.
142
143.. doctest:: rrule
144   :options: +NORMALIZE_WHITESPACE
145
146    >>> list(rrule(WEEKLY, count=10,
147    ...            dtstart=parse("19970902T090000")))
148    [datetime.datetime(1997, 9, 2, 9, 0),
149     datetime.datetime(1997, 9, 9, 9, 0),
150     datetime.datetime(1997, 9, 16, 9, 0),
151     datetime.datetime(1997, 9, 23, 9, 0),
152     datetime.datetime(1997, 9, 30, 9, 0),
153     datetime.datetime(1997, 10, 7, 9, 0),
154     datetime.datetime(1997, 10, 14, 9, 0),
155     datetime.datetime(1997, 10, 21, 9, 0),
156     datetime.datetime(1997, 10, 28, 9, 0),
157     datetime.datetime(1997, 11, 4, 9, 0)]
158
159Every other week, 6 occurrences.
160
161.. doctest:: rrule
162   :options: +NORMALIZE_WHITESPACE
163
164    >>> list(rrule(WEEKLY, interval=2, count=6,
165    ...            dtstart=parse("19970902T090000")))
166    [datetime.datetime(1997, 9, 2, 9, 0),
167     datetime.datetime(1997, 9, 16, 9, 0),
168     datetime.datetime(1997, 9, 30, 9, 0),
169     datetime.datetime(1997, 10, 14, 9, 0),
170     datetime.datetime(1997, 10, 28, 9, 0),
171     datetime.datetime(1997, 11, 11, 9, 0)]
172
173Weekly on Tuesday and Thursday for 5 weeks.
174
175.. doctest:: rrule
176   :options: +NORMALIZE_WHITESPACE
177
178    >>> list(rrule(WEEKLY, count=10, wkst=SU, byweekday=(TU,TH),
179    ...            dtstart=parse("19970902T090000")))
180    [datetime.datetime(1997, 9, 2, 9, 0),
181     datetime.datetime(1997, 9, 4, 9, 0),
182     datetime.datetime(1997, 9, 9, 9, 0),
183     datetime.datetime(1997, 9, 11, 9, 0),
184     datetime.datetime(1997, 9, 16, 9, 0),
185     datetime.datetime(1997, 9, 18, 9, 0),
186     datetime.datetime(1997, 9, 23, 9, 0),
187     datetime.datetime(1997, 9, 25, 9, 0),
188     datetime.datetime(1997, 9, 30, 9, 0),
189     datetime.datetime(1997, 10, 2, 9, 0)]
190
191Every other week on Tuesday and Thursday, for 8 occurrences.
192
193.. doctest:: rrule
194   :options: +NORMALIZE_WHITESPACE
195
196    >>> list(rrule(WEEKLY, interval=2, count=8,
197    ...            wkst=SU, byweekday=(TU,TH),
198    ...            dtstart=parse("19970902T090000")))
199    [datetime.datetime(1997, 9, 2, 9, 0),
200     datetime.datetime(1997, 9, 4, 9, 0),
201     datetime.datetime(1997, 9, 16, 9, 0),
202     datetime.datetime(1997, 9, 18, 9, 0),
203     datetime.datetime(1997, 9, 30, 9, 0),
204     datetime.datetime(1997, 10, 2, 9, 0),
205     datetime.datetime(1997, 10, 14, 9, 0),
206     datetime.datetime(1997, 10, 16, 9, 0)]
207
208Monthly on the 1st Friday for ten occurrences.
209
210.. doctest:: rrule
211   :options: +NORMALIZE_WHITESPACE
212
213    >>> list(rrule(MONTHLY, count=10, byweekday=FR(1),
214    ...            dtstart=parse("19970905T090000")))
215    [datetime.datetime(1997, 9, 5, 9, 0),
216     datetime.datetime(1997, 10, 3, 9, 0),
217     datetime.datetime(1997, 11, 7, 9, 0),
218     datetime.datetime(1997, 12, 5, 9, 0),
219     datetime.datetime(1998, 1, 2, 9, 0),
220     datetime.datetime(1998, 2, 6, 9, 0),
221     datetime.datetime(1998, 3, 6, 9, 0),
222     datetime.datetime(1998, 4, 3, 9, 0),
223     datetime.datetime(1998, 5, 1, 9, 0),
224     datetime.datetime(1998, 6, 5, 9, 0)]
225
226Every other month on the 1st and last Sunday of the month for 10 occurrences.
227
228.. doctest:: rrule
229   :options: +NORMALIZE_WHITESPACE
230
231    >>> list(rrule(MONTHLY, interval=2, count=10,
232    ...            byweekday=(SU(1), SU(-1)),
233    ...            dtstart=parse("19970907T090000")))
234    [datetime.datetime(1997, 9, 7, 9, 0),
235     datetime.datetime(1997, 9, 28, 9, 0),
236     datetime.datetime(1997, 11, 2, 9, 0),
237     datetime.datetime(1997, 11, 30, 9, 0),
238     datetime.datetime(1998, 1, 4, 9, 0),
239     datetime.datetime(1998, 1, 25, 9, 0),
240     datetime.datetime(1998, 3, 1, 9, 0),
241     datetime.datetime(1998, 3, 29, 9, 0),
242     datetime.datetime(1998, 5, 3, 9, 0),
243     datetime.datetime(1998, 5, 31, 9, 0)]
244
245Monthly on the second to last Monday of the month for 6 months.
246
247.. doctest:: rrule
248   :options: +NORMALIZE_WHITESPACE
249
250    >>> list(rrule(MONTHLY, count=6, byweekday=MO(-2),
251    ...            dtstart=parse("19970922T090000")))
252    [datetime.datetime(1997, 9, 22, 9, 0),
253     datetime.datetime(1997, 10, 20, 9, 0),
254     datetime.datetime(1997, 11, 17, 9, 0),
255     datetime.datetime(1997, 12, 22, 9, 0),
256     datetime.datetime(1998, 1, 19, 9, 0),
257     datetime.datetime(1998, 2, 16, 9, 0)]
258
259
260Monthly on the third to the last day of the month, for 6 months.
261
262.. doctest:: rrule
263   :options: +NORMALIZE_WHITESPACE
264
265    >>> list(rrule(MONTHLY, count=6, bymonthday=-3,
266    ...            dtstart=parse("19970928T090000")))
267    [datetime.datetime(1997, 9, 28, 9, 0),
268     datetime.datetime(1997, 10, 29, 9, 0),
269     datetime.datetime(1997, 11, 28, 9, 0),
270     datetime.datetime(1997, 12, 29, 9, 0),
271     datetime.datetime(1998, 1, 29, 9, 0),
272     datetime.datetime(1998, 2, 26, 9, 0)]
273
274
275Monthly on the 2nd and 15th of the month for 5 occurrences.
276
277.. doctest:: rrule
278   :options: +NORMALIZE_WHITESPACE
279
280    >>> list(rrule(MONTHLY, count=5, bymonthday=(2,15),
281    ...            dtstart=parse("19970902T090000")))
282    [datetime.datetime(1997, 9, 2, 9, 0),
283     datetime.datetime(1997, 9, 15, 9, 0),
284     datetime.datetime(1997, 10, 2, 9, 0),
285     datetime.datetime(1997, 10, 15, 9, 0),
286     datetime.datetime(1997, 11, 2, 9, 0)]
287
288
289Monthly on the first and last day of the month for 3 occurrences.
290
291.. doctest:: rrule
292   :options: +NORMALIZE_WHITESPACE
293
294    >>> list(rrule(MONTHLY, count=5, bymonthday=(-1,1,),
295    ...            dtstart=parse("19970902T090000")))
296    [datetime.datetime(1997, 9, 30, 9, 0),
297     datetime.datetime(1997, 10, 1, 9, 0),
298     datetime.datetime(1997, 10, 31, 9, 0),
299     datetime.datetime(1997, 11, 1, 9, 0),
300     datetime.datetime(1997, 11, 30, 9, 0)]
301
302
303Every 18 months on the 10th thru 15th of the month for 10 occurrences.
304
305.. doctest:: rrule
306   :options: +NORMALIZE_WHITESPACE
307
308    >>> list(rrule(MONTHLY, interval=18, count=10,
309    ...            bymonthday=range(10,16),
310    ...            dtstart=parse("19970910T090000")))
311    [datetime.datetime(1997, 9, 10, 9, 0),
312     datetime.datetime(1997, 9, 11, 9, 0),
313     datetime.datetime(1997, 9, 12, 9, 0),
314     datetime.datetime(1997, 9, 13, 9, 0),
315     datetime.datetime(1997, 9, 14, 9, 0),
316     datetime.datetime(1997, 9, 15, 9, 0),
317     datetime.datetime(1999, 3, 10, 9, 0),
318     datetime.datetime(1999, 3, 11, 9, 0),
319     datetime.datetime(1999, 3, 12, 9, 0),
320     datetime.datetime(1999, 3, 13, 9, 0)]
321
322
323Every Tuesday, every other month, 6 occurences.
324
325.. doctest:: rrule
326   :options: +NORMALIZE_WHITESPACE
327
328    >>> list(rrule(MONTHLY, interval=2, count=6, byweekday=TU,
329    ...            dtstart=parse("19970902T090000")))
330    [datetime.datetime(1997, 9, 2, 9, 0),
331     datetime.datetime(1997, 9, 9, 9, 0),
332     datetime.datetime(1997, 9, 16, 9, 0),
333     datetime.datetime(1997, 9, 23, 9, 0),
334     datetime.datetime(1997, 9, 30, 9, 0),
335     datetime.datetime(1997, 11, 4, 9, 0)]
336
337
338Yearly in June and July for 10 occurrences.
339
340.. doctest:: rrule
341   :options: +NORMALIZE_WHITESPACE
342
343    >>> list(rrule(YEARLY, count=4, bymonth=(6,7),
344    ...            dtstart=parse("19970610T090000")))
345    [datetime.datetime(1997, 6, 10, 9, 0),
346     datetime.datetime(1997, 7, 10, 9, 0),
347     datetime.datetime(1998, 6, 10, 9, 0),
348     datetime.datetime(1998, 7, 10, 9, 0)]
349
350
351Every 3rd year on the 1st, 100th and 200th day for 4 occurrences.
352
353.. doctest:: rrule
354   :options: +NORMALIZE_WHITESPACE
355
356    >>> list(rrule(YEARLY, count=4, interval=3, byyearday=(1,100,200),
357    ...            dtstart=parse("19970101T090000")))
358    [datetime.datetime(1997, 1, 1, 9, 0),
359     datetime.datetime(1997, 4, 10, 9, 0),
360     datetime.datetime(1997, 7, 19, 9, 0),
361     datetime.datetime(2000, 1, 1, 9, 0)]
362
363
364Every 20th Monday of the year, 3 occurrences.
365
366.. doctest:: rrule
367   :options: +NORMALIZE_WHITESPACE
368
369    >>> list(rrule(YEARLY, count=3, byweekday=MO(20),
370    ...            dtstart=parse("19970519T090000")))
371    [datetime.datetime(1997, 5, 19, 9, 0),
372     datetime.datetime(1998, 5, 18, 9, 0),
373     datetime.datetime(1999, 5, 17, 9, 0)]
374
375
376Monday of week number 20 (where the default start of the week is Monday),
3773 occurrences.
378
379.. doctest:: rrule
380   :options: +NORMALIZE_WHITESPACE
381
382    >>> list(rrule(YEARLY, count=3, byweekno=20, byweekday=MO,
383    ...            dtstart=parse("19970512T090000")))
384    [datetime.datetime(1997, 5, 12, 9, 0),
385     datetime.datetime(1998, 5, 11, 9, 0),
386     datetime.datetime(1999, 5, 17, 9, 0)]
387
388
389The week number 1 may be in the last year.
390
391.. doctest:: rrule
392   :options: +NORMALIZE_WHITESPACE
393
394    >>> list(rrule(WEEKLY, count=3, byweekno=1, byweekday=MO,
395    ...            dtstart=parse("19970902T090000")))
396    [datetime.datetime(1997, 12, 29, 9, 0),
397     datetime.datetime(1999, 1, 4, 9, 0),
398     datetime.datetime(2000, 1, 3, 9, 0)]
399
400
401And the week numbers greater than 51 may be in the next year.
402
403.. doctest:: rrule
404   :options: +NORMALIZE_WHITESPACE
405
406    >>> list(rrule(WEEKLY, count=3, byweekno=52, byweekday=SU,
407    ...            dtstart=parse("19970902T090000")))
408    [datetime.datetime(1997, 12, 28, 9, 0),
409     datetime.datetime(1998, 12, 27, 9, 0),
410     datetime.datetime(2000, 1, 2, 9, 0)]
411
412
413Only some years have week number 53:
414
415.. doctest:: rrule
416   :options: +NORMALIZE_WHITESPACE
417
418    >>> list(rrule(WEEKLY, count=3, byweekno=53, byweekday=MO,
419    ...            dtstart=parse("19970902T090000")))
420    [datetime.datetime(1998, 12, 28, 9, 0),
421     datetime.datetime(2004, 12, 27, 9, 0),
422     datetime.datetime(2009, 12, 28, 9, 0)]
423
424
425Every Friday the 13th, 4 occurrences.
426
427.. doctest:: rrule
428   :options: +NORMALIZE_WHITESPACE
429
430    >>> list(rrule(YEARLY, count=4, byweekday=FR, bymonthday=13,
431    ...            dtstart=parse("19970902T090000")))
432    [datetime.datetime(1998, 2, 13, 9, 0),
433     datetime.datetime(1998, 3, 13, 9, 0),
434     datetime.datetime(1998, 11, 13, 9, 0),
435     datetime.datetime(1999, 8, 13, 9, 0)]
436
437
438Every four years, the first Tuesday after a Monday in November,
4393 occurrences (U.S. Presidential Election day):
440
441.. doctest:: rrule
442   :options: +NORMALIZE_WHITESPACE
443
444    >>> list(rrule(YEARLY, interval=4, count=3, bymonth=11,
445    ...            byweekday=TU, bymonthday=(2,3,4,5,6,7,8),
446    ...            dtstart=parse("19961105T090000")))
447    [datetime.datetime(1996, 11, 5, 9, 0),
448     datetime.datetime(2000, 11, 7, 9, 0),
449     datetime.datetime(2004, 11, 2, 9, 0)]
450
451
452The 3rd instance into the month of one of Tuesday, Wednesday or
453Thursday, for the next 3 months:
454
455.. doctest:: rrule
456   :options: +NORMALIZE_WHITESPACE
457
458    >>> list(rrule(MONTHLY, count=3, byweekday=(TU,WE,TH),
459    ...            bysetpos=3, dtstart=parse("19970904T090000")))
460    [datetime.datetime(1997, 9, 4, 9, 0),
461     datetime.datetime(1997, 10, 7, 9, 0),
462     datetime.datetime(1997, 11, 6, 9, 0)]
463
464
465The 2nd to last weekday of the month, 3 occurrences.
466
467.. doctest:: rrule
468   :options: +NORMALIZE_WHITESPACE
469
470    >>> list(rrule(MONTHLY, count=3, byweekday=(MO,TU,WE,TH,FR),
471    ...            bysetpos=-2, dtstart=parse("19970929T090000")))
472    [datetime.datetime(1997, 9, 29, 9, 0),
473     datetime.datetime(1997, 10, 30, 9, 0),
474     datetime.datetime(1997, 11, 27, 9, 0)]
475
476
477Every 3 hours from 9:00 AM to 5:00 PM on a specific day.
478
479.. doctest:: rrule
480   :options: +NORMALIZE_WHITESPACE
481
482    >>> list(rrule(HOURLY, interval=3,
483    ...            dtstart=parse("19970902T090000"),
484    ...            until=parse("19970902T170000")))
485    [datetime.datetime(1997, 9, 2, 9, 0),
486     datetime.datetime(1997, 9, 2, 12, 0),
487     datetime.datetime(1997, 9, 2, 15, 0)]
488
489
490Every 15 minutes for 6 occurrences.
491
492.. doctest:: rrule
493   :options: +NORMALIZE_WHITESPACE
494
495    >>> list(rrule(MINUTELY, interval=15, count=6,
496    ...            dtstart=parse("19970902T090000")))
497    [datetime.datetime(1997, 9, 2, 9, 0),
498     datetime.datetime(1997, 9, 2, 9, 15),
499     datetime.datetime(1997, 9, 2, 9, 30),
500     datetime.datetime(1997, 9, 2, 9, 45),
501     datetime.datetime(1997, 9, 2, 10, 0),
502     datetime.datetime(1997, 9, 2, 10, 15)]
503
504
505Every hour and a half for 4 occurrences.
506
507.. doctest:: rrule
508   :options: +NORMALIZE_WHITESPACE
509
510    >>> list(rrule(MINUTELY, interval=90, count=4,
511    ...            dtstart=parse("19970902T090000")))
512    [datetime.datetime(1997, 9, 2, 9, 0),
513     datetime.datetime(1997, 9, 2, 10, 30),
514     datetime.datetime(1997, 9, 2, 12, 0),
515     datetime.datetime(1997, 9, 2, 13, 30)]
516
517
518Every 20 minutes from 9:00 AM to 4:40 PM for two days.
519
520.. doctest:: rrule
521   :options: +NORMALIZE_WHITESPACE, +ELLIPSIS
522
523    >>> list(rrule(MINUTELY, interval=20, count=48,
524    ...            byhour=range(9,17), byminute=(0,20,40),
525    ...            dtstart=parse("19970902T090000")))
526    [datetime.datetime(1997, 9, 2, 9, 0),
527     datetime.datetime(1997, 9, 2, 9, 20),
528     ...
529     datetime.datetime(1997, 9, 2, 16, 20),
530     datetime.datetime(1997, 9, 2, 16, 40),
531     datetime.datetime(1997, 9, 3, 9, 0),
532     datetime.datetime(1997, 9, 3, 9, 20),
533     ...
534     datetime.datetime(1997, 9, 3, 16, 20),
535     datetime.datetime(1997, 9, 3, 16, 40)]
536
537
538An example where the days generated makes a difference because of `wkst`.
539
540.. doctest:: rrule
541   :options: +NORMALIZE_WHITESPACE
542
543    >>> list(rrule(WEEKLY, interval=2, count=4,
544    ...            byweekday=(TU,SU), wkst=MO,
545    ...            dtstart=parse("19970805T090000")))
546    [datetime.datetime(1997, 8, 5, 9, 0),
547     datetime.datetime(1997, 8, 10, 9, 0),
548     datetime.datetime(1997, 8, 19, 9, 0),
549     datetime.datetime(1997, 8, 24, 9, 0)]
550
551    >>> list(rrule(WEEKLY, interval=2, count=4,
552    ...            byweekday=(TU,SU), wkst=SU,
553    ...            dtstart=parse("19970805T090000")))
554    [datetime.datetime(1997, 8, 5, 9, 0),
555     datetime.datetime(1997, 8, 17, 9, 0),
556     datetime.datetime(1997, 8, 19, 9, 0),
557     datetime.datetime(1997, 8, 31, 9, 0)]
558
559
560rruleset examples
561-----------------
562Daily, for 7 days, jumping Saturday and Sunday occurrences.
563
564.. testsetup:: rruleset
565
566    import datetime
567
568    from dateutil.parser import parse
569    from dateutil.rrule import rrule, rruleset
570    from dateutil.rrule import YEARLY, MONTHLY, WEEKLY, DAILY
571    from dateutil.rrule import MO, TU, WE, TH, FR, SA, SU
572
573    import pprint
574    import sys
575    sys.displayhook = pprint.pprint
576
577.. doctest:: rruleset
578   :options: +NORMALIZE_WHITESPACE
579
580    >>> set = rruleset()
581    >>> set.rrule(rrule(DAILY, count=7,
582    ...                 dtstart=parse("19970902T090000")))
583    >>> set.exrule(rrule(YEARLY, byweekday=(SA,SU),
584    ...                  dtstart=parse("19970902T090000")))
585    >>> list(set)
586    [datetime.datetime(1997, 9, 2, 9, 0),
587     datetime.datetime(1997, 9, 3, 9, 0),
588     datetime.datetime(1997, 9, 4, 9, 0),
589     datetime.datetime(1997, 9, 5, 9, 0),
590     datetime.datetime(1997, 9, 8, 9, 0)]
591
592
593Weekly, for 4 weeks, plus one time on day 7, and not on day 16.
594
595.. doctest:: rruleset
596   :options: +NORMALIZE_WHITESPACE
597
598    >>> set = rruleset()
599    >>> set.rrule(rrule(WEEKLY, count=4,
600    ...           dtstart=parse("19970902T090000")))
601    >>> set.rdate(datetime.datetime(1997, 9, 7, 9, 0))
602    >>> set.exdate(datetime.datetime(1997, 9, 16, 9, 0))
603    >>> list(set)
604    [datetime.datetime(1997, 9, 2, 9, 0),
605     datetime.datetime(1997, 9, 7, 9, 0),
606     datetime.datetime(1997, 9, 9, 9, 0),
607     datetime.datetime(1997, 9, 23, 9, 0)]
608
609
610rrulestr() examples
611-------------------
612
613Every 10 days, 5 occurrences.
614
615.. testsetup:: rrulestr
616
617    from dateutil.parser import parse
618    from dateutil.rrule import rruleset, rrulestr
619
620    import pprint
621    import sys
622    sys.displayhook = pprint.pprint
623
624.. doctest:: rrulestr
625   :options: +NORMALIZE_WHITESPACE
626
627    >>> list(rrulestr("""
628    ... DTSTART:19970902T090000
629    ... RRULE:FREQ=DAILY;INTERVAL=10;COUNT=5
630    ... """))
631    [datetime.datetime(1997, 9, 2, 9, 0),
632     datetime.datetime(1997, 9, 12, 9, 0),
633     datetime.datetime(1997, 9, 22, 9, 0),
634     datetime.datetime(1997, 10, 2, 9, 0),
635     datetime.datetime(1997, 10, 12, 9, 0)]
636
637
638Same thing, but passing only the `RRULE` value.
639
640.. doctest:: rrulestr
641   :options: +NORMALIZE_WHITESPACE
642
643    >>> list(rrulestr("FREQ=DAILY;INTERVAL=10;COUNT=5",
644    ...               dtstart=parse("19970902T090000")))
645    [datetime.datetime(1997, 9, 2, 9, 0),
646     datetime.datetime(1997, 9, 12, 9, 0),
647     datetime.datetime(1997, 9, 22, 9, 0),
648     datetime.datetime(1997, 10, 2, 9, 0),
649     datetime.datetime(1997, 10, 12, 9, 0)]
650
651
652Notice that when using a single rule, it returns an
653`rrule` instance, unless `forceset` was used.
654
655.. doctest:: rrulestr
656   :options: +ELLIPSIS
657
658    >>> rrulestr("FREQ=DAILY;INTERVAL=10;COUNT=5")
659    <dateutil.rrule.rrule object at 0x...>
660
661    >>> rrulestr("""
662    ... DTSTART:19970902T090000
663    ... RRULE:FREQ=DAILY;INTERVAL=10;COUNT=5
664    ... """)
665    <dateutil.rrule.rrule object at 0x...>
666
667    >>> rrulestr("FREQ=DAILY;INTERVAL=10;COUNT=5", forceset=True)
668    <dateutil.rrule.rruleset object at 0x...>
669
670
671But when an `rruleset` is needed, it is automatically used.
672
673.. doctest:: rrulestr
674   :options: +ELLIPSIS
675
676    >>> rrulestr("""
677    ... DTSTART:19970902T090000
678    ... RRULE:FREQ=DAILY;INTERVAL=10;COUNT=5
679    ... RRULE:FREQ=DAILY;INTERVAL=5;COUNT=3
680    ... """)
681    <dateutil.rrule.rruleset object at 0x...>
682