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