1
# -*- coding: utf-8 -*-
2 84
from __future__ import unicode_literals
3

4 84
from datetime import datetime, date
5 84
import unittest
6 84
from six import PY2
7

8 84
from dateutil import tz
9 84
from dateutil.rrule import (
10
    rrule, rruleset, rrulestr,
11
    YEARLY, MONTHLY, WEEKLY, DAILY,
12
    HOURLY, MINUTELY, SECONDLY,
13
    MO, TU, WE, TH, FR, SA, SU
14
)
15

16 84
from freezegun import freeze_time
17

18 84
import pytest
19

20

21 84
@pytest.mark.rrule
22 84
class RRuleTest(unittest.TestCase):
23 84
    def _rrulestr_reverse_test(self, rule):
24
        """
25
        Call with an `rrule` and it will test that `str(rrule)` generates a
26
        string which generates the same `rrule` as the input when passed to
27
        `rrulestr()`
28
        """
29 84
        rr_str = str(rule)
30 84
        rrulestr_rrule = rrulestr(rr_str)
31

32 84
        self.assertEqual(list(rule), list(rrulestr_rrule))
33

34 84
    def testStrAppendRRULEToken(self):
35
        # `_rrulestr_reverse_test` does not check if the "RRULE:" prefix
36
        # property is appended properly, so give it a dedicated test
37 84
        self.assertEqual(str(rrule(YEARLY,
38
                             count=5,
39
                             dtstart=datetime(1997, 9, 2, 9, 0))),
40
                         "DTSTART:19970902T090000\n"
41
                         "RRULE:FREQ=YEARLY;COUNT=5")
42

43 84
        rr_str = (
44
          'DTSTART:19970105T083000\nRRULE:FREQ=YEARLY;INTERVAL=2'
45
        )
46 84
        self.assertEqual(str(rrulestr(rr_str)), rr_str)
47

48 84
    def testYearly(self):
49 84
        self.assertEqual(list(rrule(YEARLY,
50
                              count=3,
51
                              dtstart=datetime(1997, 9, 2, 9, 0))),
52
                         [datetime(1997, 9, 2, 9, 0),
53
                          datetime(1998, 9, 2, 9, 0),
54
                          datetime(1999, 9, 2, 9, 0)])
55

56 84
    def testYearlyInterval(self):
57 84
        self.assertEqual(list(rrule(YEARLY,
58
                              count=3,
59
                              interval=2,
60
                              dtstart=datetime(1997, 9, 2, 9, 0))),
61
                         [datetime(1997, 9, 2, 9, 0),
62
                          datetime(1999, 9, 2, 9, 0),
63
                          datetime(2001, 9, 2, 9, 0)])
64

65 84
    def testYearlyIntervalLarge(self):
66 84
        self.assertEqual(list(rrule(YEARLY,
67
                              count=3,
68
                              interval=100,
69
                              dtstart=datetime(1997, 9, 2, 9, 0))),
70
                         [datetime(1997, 9, 2, 9, 0),
71
                          datetime(2097, 9, 2, 9, 0),
72
                          datetime(2197, 9, 2, 9, 0)])
73

74 84
    def testYearlyByMonth(self):
75 84
        self.assertEqual(list(rrule(YEARLY,
76
                              count=3,
77
                              bymonth=(1, 3),
78
                              dtstart=datetime(1997, 9, 2, 9, 0))),
79
                         [datetime(1998, 1, 2, 9, 0),
80
                          datetime(1998, 3, 2, 9, 0),
81
                          datetime(1999, 1, 2, 9, 0)])
82

83 84
    def testYearlyByMonthDay(self):
84 84
        self.assertEqual(list(rrule(YEARLY,
85
                              count=3,
86
                              bymonthday=(1, 3),
87
                              dtstart=datetime(1997, 9, 2, 9, 0))),
88
                         [datetime(1997, 9, 3, 9, 0),
89
                          datetime(1997, 10, 1, 9, 0),
90
                          datetime(1997, 10, 3, 9, 0)])
91

92 84
    def testYearlyByMonthAndMonthDay(self):
93 84
        self.assertEqual(list(rrule(YEARLY,
94
                              count=3,
95
                              bymonth=(1, 3),
96
                              bymonthday=(5, 7),
97
                              dtstart=datetime(1997, 9, 2, 9, 0))),
98
                         [datetime(1998, 1, 5, 9, 0),
99
                          datetime(1998, 1, 7, 9, 0),
100
                          datetime(1998, 3, 5, 9, 0)])
101

102 84
    def testYearlyByWeekDay(self):
103 84
        self.assertEqual(list(rrule(YEARLY,
104
                              count=3,
105
                              byweekday=(TU, TH),
106
                              dtstart=datetime(1997, 9, 2, 9, 0))),
107
                         [datetime(1997, 9, 2, 9, 0),
108
                          datetime(1997, 9, 4, 9, 0),
109
                          datetime(1997, 9, 9, 9, 0)])
110

111 84
    def testYearlyByNWeekDay(self):
112 84
        self.assertEqual(list(rrule(YEARLY,
113
                              count=3,
114
                              byweekday=(TU(1), TH(-1)),
115
                              dtstart=datetime(1997, 9, 2, 9, 0))),
116
                         [datetime(1997, 12, 25, 9, 0),
117
                          datetime(1998, 1, 6, 9, 0),
118
                          datetime(1998, 12, 31, 9, 0)])
119

120 84
    def testYearlyByNWeekDayLarge(self):
121 84
        self.assertEqual(list(rrule(YEARLY,
122
                              count=3,
123
                              byweekday=(TU(3), TH(-3)),
124
                              dtstart=datetime(1997, 9, 2, 9, 0))),
125
                         [datetime(1997, 12, 11, 9, 0),
126
                          datetime(1998, 1, 20, 9, 0),
127
                          datetime(1998, 12, 17, 9, 0)])
128

129 84
    def testYearlyByMonthAndWeekDay(self):
130 84
        self.assertEqual(list(rrule(YEARLY,
131
                              count=3,
132
                              bymonth=(1, 3),
133
                              byweekday=(TU, TH),
134
                              dtstart=datetime(1997, 9, 2, 9, 0))),
135
                         [datetime(1998, 1, 1, 9, 0),
136
                          datetime(1998, 1, 6, 9, 0),
137
                          datetime(1998, 1, 8, 9, 0)])
138

139 84
    def testYearlyByMonthAndNWeekDay(self):
140 84
        self.assertEqual(list(rrule(YEARLY,
141
                              count=3,
142
                              bymonth=(1, 3),
143
                              byweekday=(TU(1), TH(-1)),
144
                              dtstart=datetime(1997, 9, 2, 9, 0))),
145
                         [datetime(1998, 1, 6, 9, 0),
146
                          datetime(1998, 1, 29, 9, 0),
147
                          datetime(1998, 3, 3, 9, 0)])
148

149 84
    def testYearlyByMonthAndNWeekDayLarge(self):
150
        # This is interesting because the TH(-3) ends up before
151
        # the TU(3).
152 84
        self.assertEqual(list(rrule(YEARLY,
153
                              count=3,
154
                              bymonth=(1, 3),
155
                              byweekday=(TU(3), TH(-3)),
156
                              dtstart=datetime(1997, 9, 2, 9, 0))),
157
                         [datetime(1998, 1, 15, 9, 0),
158
                          datetime(1998, 1, 20, 9, 0),
159
                          datetime(1998, 3, 12, 9, 0)])
160

161 84
    def testYearlyByMonthDayAndWeekDay(self):
162 84
        self.assertEqual(list(rrule(YEARLY,
163
                              count=3,
164
                              bymonthday=(1, 3),
165
                              byweekday=(TU, TH),
166
                              dtstart=datetime(1997, 9, 2, 9, 0))),
167
                         [datetime(1998, 1, 1, 9, 0),
168
                          datetime(1998, 2, 3, 9, 0),
169
                          datetime(1998, 3, 3, 9, 0)])
170

171 84
    def testYearlyByMonthAndMonthDayAndWeekDay(self):
172 84
        self.assertEqual(list(rrule(YEARLY,
173
                              count=3,
174
                              bymonth=(1, 3),
175
                              bymonthday=(1, 3),
176
                              byweekday=(TU, TH),
177
                              dtstart=datetime(1997, 9, 2, 9, 0))),
178
                         [datetime(1998, 1, 1, 9, 0),
179
                          datetime(1998, 3, 3, 9, 0),
180
                          datetime(2001, 3, 1, 9, 0)])
181

182 84
    def testYearlyByYearDay(self):
183 84
        self.assertEqual(list(rrule(YEARLY,
184
                              count=4,
185
                              byyearday=(1, 100, 200, 365),
186
                              dtstart=datetime(1997, 9, 2, 9, 0))),
187
                         [datetime(1997, 12, 31, 9, 0),
188
                          datetime(1998, 1, 1, 9, 0),
189
                          datetime(1998, 4, 10, 9, 0),
190
                          datetime(1998, 7, 19, 9, 0)])
191

192 84
    def testYearlyByYearDayNeg(self):
193 84
        self.assertEqual(list(rrule(YEARLY,
194
                              count=4,
195
                              byyearday=(-365, -266, -166, -1),
196
                              dtstart=datetime(1997, 9, 2, 9, 0))),
197
                         [datetime(1997, 12, 31, 9, 0),
198
                          datetime(1998, 1, 1, 9, 0),
199
                          datetime(1998, 4, 10, 9, 0),
200
                          datetime(1998, 7, 19, 9, 0)])
201

202 84
    def testYearlyByMonthAndYearDay(self):
203 84
        self.assertEqual(list(rrule(YEARLY,
204
                              count=4,
205
                              bymonth=(4, 7),
206
                              byyearday=(1, 100, 200, 365),
207
                              dtstart=datetime(1997, 9, 2, 9, 0))),
208
                         [datetime(1998, 4, 10, 9, 0),
209
                          datetime(1998, 7, 19, 9, 0),
210
                          datetime(1999, 4, 10, 9, 0),
211
                          datetime(1999, 7, 19, 9, 0)])
212

213 84
    def testYearlyByMonthAndYearDayNeg(self):
214 84
        self.assertEqual(list(rrule(YEARLY,
215
                              count=4,
216
                              bymonth=(4, 7),
217
                              byyearday=(-365, -266, -166, -1),
218
                              dtstart=datetime(1997, 9, 2, 9, 0))),
219
                         [datetime(1998, 4, 10, 9, 0),
220
                          datetime(1998, 7, 19, 9, 0),
221
                          datetime(1999, 4, 10, 9, 0),
222
                          datetime(1999, 7, 19, 9, 0)])
223

224 84
    def testYearlyByWeekNo(self):
225 84
        self.assertEqual(list(rrule(YEARLY,
226
                              count=3,
227
                              byweekno=20,
228
                              dtstart=datetime(1997, 9, 2, 9, 0))),
229
                         [datetime(1998, 5, 11, 9, 0),
230
                          datetime(1998, 5, 12, 9, 0),
231
                          datetime(1998, 5, 13, 9, 0)])
232

233 84
    def testYearlyByWeekNoAndWeekDay(self):
234
        # That's a nice one. The first days of week number one
235
        # may be in the last year.
236 84
        self.assertEqual(list(rrule(YEARLY,
237
                              count=3,
238
                              byweekno=1,
239
                              byweekday=MO,
240
                              dtstart=datetime(1997, 9, 2, 9, 0))),
241
                         [datetime(1997, 12, 29, 9, 0),
242
                          datetime(1999, 1, 4, 9, 0),
243
                          datetime(2000, 1, 3, 9, 0)])
244

245 84
    def testYearlyByWeekNoAndWeekDayLarge(self):
246
        # Another nice test. The last days of week number 52/53
247
        # may be in the next year.
248 84
        self.assertEqual(list(rrule(YEARLY,
249
                              count=3,
250
                              byweekno=52,
251
                              byweekday=SU,
252
                              dtstart=datetime(1997, 9, 2, 9, 0))),
253
                         [datetime(1997, 12, 28, 9, 0),
254
                          datetime(1998, 12, 27, 9, 0),
255
                          datetime(2000, 1, 2, 9, 0)])
256

257 84
    def testYearlyByWeekNoAndWeekDayLast(self):
258 84
        self.assertEqual(list(rrule(YEARLY,
259
                              count=3,
260
                              byweekno=-1,
261
                              byweekday=SU,
262
                              dtstart=datetime(1997, 9, 2, 9, 0))),
263
                         [datetime(1997, 12, 28, 9, 0),
264
                          datetime(1999, 1, 3, 9, 0),
265
                          datetime(2000, 1, 2, 9, 0)])
266

267 84
    def testYearlyByEaster(self):
268 84
        self.assertEqual(list(rrule(YEARLY,
269
                              count=3,
270
                              byeaster=0,
271
                              dtstart=datetime(1997, 9, 2, 9, 0))),
272
                         [datetime(1998, 4, 12, 9, 0),
273
                          datetime(1999, 4, 4, 9, 0),
274
                          datetime(2000, 4, 23, 9, 0)])
275

276 84
    def testYearlyByEasterPos(self):
277 84
        self.assertEqual(list(rrule(YEARLY,
278
                              count=3,
279
                              byeaster=1,
280
                              dtstart=datetime(1997, 9, 2, 9, 0))),
281
                         [datetime(1998, 4, 13, 9, 0),
282
                          datetime(1999, 4, 5, 9, 0),
283
                          datetime(2000, 4, 24, 9, 0)])
284

285 84
    def testYearlyByEasterNeg(self):
286 84
        self.assertEqual(list(rrule(YEARLY,
287
                              count=3,
288
                              byeaster=-1,
289
                              dtstart=datetime(1997, 9, 2, 9, 0))),
290
                         [datetime(1998, 4, 11, 9, 0),
291
                          datetime(1999, 4, 3, 9, 0),
292
                          datetime(2000, 4, 22, 9, 0)])
293

294 84
    def testYearlyByWeekNoAndWeekDay53(self):
295 84
        self.assertEqual(list(rrule(YEARLY,
296
                              count=3,
297
                              byweekno=53,
298
                              byweekday=MO,
299
                              dtstart=datetime(1997, 9, 2, 9, 0))),
300
                         [datetime(1998, 12, 28, 9, 0),
301
                          datetime(2004, 12, 27, 9, 0),
302
                          datetime(2009, 12, 28, 9, 0)])
303

304 84
    def testYearlyByHour(self):
305 84
        self.assertEqual(list(rrule(YEARLY,
306
                              count=3,
307
                              byhour=(6, 18),
308
                              dtstart=datetime(1997, 9, 2, 9, 0))),
309
                         [datetime(1997, 9, 2, 18, 0),
310
                          datetime(1998, 9, 2, 6, 0),
311
                          datetime(1998, 9, 2, 18, 0)])
312

313 84
    def testYearlyByMinute(self):
314 84
        self.assertEqual(list(rrule(YEARLY,
315
                              count=3,
316
                              byminute=(6, 18),
317
                              dtstart=datetime(1997, 9, 2, 9, 0))),
318
                         [datetime(1997, 9, 2, 9, 6),
319
                          datetime(1997, 9, 2, 9, 18),
320
                          datetime(1998, 9, 2, 9, 6)])
321

322 84
    def testYearlyBySecond(self):
323 84
        self.assertEqual(list(rrule(YEARLY,
324
                              count=3,
325
                              bysecond=(6, 18),
326
                              dtstart=datetime(1997, 9, 2, 9, 0))),
327
                         [datetime(1997, 9, 2, 9, 0, 6),
328
                          datetime(1997, 9, 2, 9, 0, 18),
329
                          datetime(1998, 9, 2, 9, 0, 6)])
330

331 84
    def testYearlyByHourAndMinute(self):
332 84
        self.assertEqual(list(rrule(YEARLY,
333
                              count=3,
334
                              byhour=(6, 18),
335
                              byminute=(6, 18),
336
                              dtstart=datetime(1997, 9, 2, 9, 0))),
337
                         [datetime(1997, 9, 2, 18, 6),
338
                          datetime(1997, 9, 2, 18, 18),
339
                          datetime(1998, 9, 2, 6, 6)])
340

341 84
    def testYearlyByHourAndSecond(self):
342 84
        self.assertEqual(list(rrule(YEARLY,
343
                              count=3,
344
                              byhour=(6, 18),
345
                              bysecond=(6, 18),
346
                              dtstart=datetime(1997, 9, 2, 9, 0))),
347
                         [datetime(1997, 9, 2, 18, 0, 6),
348
                          datetime(1997, 9, 2, 18, 0, 18),
349
                          datetime(1998, 9, 2, 6, 0, 6)])
350

351 84
    def testYearlyByMinuteAndSecond(self):
352 84
        self.assertEqual(list(rrule(YEARLY,
353
                              count=3,
354
                              byminute=(6, 18),
355
                              bysecond=(6, 18),
356
                              dtstart=datetime(1997, 9, 2, 9, 0))),
357
                         [datetime(1997, 9, 2, 9, 6, 6),
358
                          datetime(1997, 9, 2, 9, 6, 18),
359
                          datetime(1997, 9, 2, 9, 18, 6)])
360

361 84
    def testYearlyByHourAndMinuteAndSecond(self):
362 84
        self.assertEqual(list(rrule(YEARLY,
363
                              count=3,
364
                              byhour=(6, 18),
365
                              byminute=(6, 18),
366
                              bysecond=(6, 18),
367
                              dtstart=datetime(1997, 9, 2, 9, 0))),
368
                         [datetime(1997, 9, 2, 18, 6, 6),
369
                          datetime(1997, 9, 2, 18, 6, 18),
370
                          datetime(1997, 9, 2, 18, 18, 6)])
371

372 84
    def testYearlyBySetPos(self):
373 84
        self.assertEqual(list(rrule(YEARLY,
374
                              count=3,
375
                              bymonthday=15,
376
                              byhour=(6, 18),
377
                              bysetpos=(3, -3),
378
                              dtstart=datetime(1997, 9, 2, 9, 0))),
379
                         [datetime(1997, 11, 15, 18, 0),
380
                          datetime(1998, 2, 15, 6, 0),
381
                          datetime(1998, 11, 15, 18, 0)])
382

383 84
    def testMonthly(self):
384 84
        self.assertEqual(list(rrule(MONTHLY,
385
                              count=3,
386
                              dtstart=datetime(1997, 9, 2, 9, 0))),
387
                         [datetime(1997, 9, 2, 9, 0),
388
                          datetime(1997, 10, 2, 9, 0),
389
                          datetime(1997, 11, 2, 9, 0)])
390

391 84
    def testMonthlyInterval(self):
392 84
        self.assertEqual(list(rrule(MONTHLY,
393
                              count=3,
394
                              interval=2,
395
                              dtstart=datetime(1997, 9, 2, 9, 0))),
396
                         [datetime(1997, 9, 2, 9, 0),
397
                          datetime(1997, 11, 2, 9, 0),
398
                          datetime(1998, 1, 2, 9, 0)])
399

400 84
    def testMonthlyIntervalLarge(self):
401 84
        self.assertEqual(list(rrule(MONTHLY,
402
                              count=3,
403
                              interval=18,
404
                              dtstart=datetime(1997, 9, 2, 9, 0))),
405
                         [datetime(1997, 9, 2, 9, 0),
406
                          datetime(1999, 3, 2, 9, 0),
407
                          datetime(2000, 9, 2, 9, 0)])
408

409 84
    def testMonthlyByMonth(self):
410 84
        self.assertEqual(list(rrule(MONTHLY,
411
                              count=3,
412
                              bymonth=(1, 3),
413
                              dtstart=datetime(1997, 9, 2, 9, 0))),
414
                         [datetime(1998, 1, 2, 9, 0),
415
                          datetime(1998, 3, 2, 9, 0),
416
                          datetime(1999, 1, 2, 9, 0)])
417

418 84
    def testMonthlyByMonthDay(self):
419 84
        self.assertEqual(list(rrule(MONTHLY,
420
                              count=3,
421
                              bymonthday=(1, 3),
422
                              dtstart=datetime(1997, 9, 2, 9, 0))),
423
                         [datetime(1997, 9, 3, 9, 0),
424
                          datetime(1997, 10, 1, 9, 0),
425
                          datetime(1997, 10, 3, 9, 0)])
426

427 84
    def testMonthlyByMonthAndMonthDay(self):
428 84
        self.assertEqual(list(rrule(MONTHLY,
429
                              count=3,
430
                              bymonth=(1, 3),
431
                              bymonthday=(5, 7),
432
                              dtstart=datetime(1997, 9, 2, 9, 0))),
433
                         [datetime(1998, 1, 5, 9, 0),
434
                          datetime(1998, 1, 7, 9, 0),
435
                          datetime(1998, 3, 5, 9, 0)])
436

437 84
    def testMonthlyByWeekDay(self):
438 84
        self.assertEqual(list(rrule(MONTHLY,
439
                              count=3,
440
                              byweekday=(TU, TH),
441
                              dtstart=datetime(1997, 9, 2, 9, 0))),
442
                         [datetime(1997, 9, 2, 9, 0),
443
                          datetime(1997, 9, 4, 9, 0),
444
                          datetime(1997, 9, 9, 9, 0)])
445

446
        # Third Monday of the month
447 84
        self.assertEqual(rrule(MONTHLY,
448
                         byweekday=(MO(+3)),
449
                         dtstart=datetime(1997, 9, 1)).between(datetime(1997, 9, 1),
450
                                                               datetime(1997, 12, 1)),
451
                         [datetime(1997, 9, 15, 0, 0),
452
                          datetime(1997, 10, 20, 0, 0),
453
                          datetime(1997, 11, 17, 0, 0)])
454

455 84
    def testMonthlyByNWeekDay(self):
456 84
        self.assertEqual(list(rrule(MONTHLY,
457
                              count=3,
458
                              byweekday=(TU(1), TH(-1)),
459
                              dtstart=datetime(1997, 9, 2, 9, 0))),
460
                         [datetime(1997, 9, 2, 9, 0),
461
                          datetime(1997, 9, 25, 9, 0),
462
                          datetime(1997, 10, 7, 9, 0)])
463

464 84
    def testMonthlyByNWeekDayLarge(self):
465 84
        self.assertEqual(list(rrule(MONTHLY,
466
                              count=3,
467
                              byweekday=(TU(3), TH(-3)),
468
                              dtstart=datetime(1997, 9, 2, 9, 0))),
469
                         [datetime(1997, 9, 11, 9, 0),
470
                          datetime(1997, 9, 16, 9, 0),
471
                          datetime(1997, 10, 16, 9, 0)])
472

473 84
    def testMonthlyByMonthAndWeekDay(self):
474 84
        self.assertEqual(list(rrule(MONTHLY,
475
                              count=3,
476
                              bymonth=(1, 3),
477
                              byweekday=(TU, TH),
478
                              dtstart=datetime(1997, 9, 2, 9, 0))),
479
                         [datetime(1998, 1, 1, 9, 0),
480
                          datetime(1998, 1, 6, 9, 0),
481
                          datetime(1998, 1, 8, 9, 0)])
482

483 84
    def testMonthlyByMonthAndNWeekDay(self):
484 84
        self.assertEqual(list(rrule(MONTHLY,
485
                              count=3,
486
                              bymonth=(1, 3),
487
                              byweekday=(TU(1), TH(-1)),
488
                              dtstart=datetime(1997, 9, 2, 9, 0))),
489
                         [datetime(1998, 1, 6, 9, 0),
490
                          datetime(1998, 1, 29, 9, 0),
491
                          datetime(1998, 3, 3, 9, 0)])
492

493 84
    def testMonthlyByMonthAndNWeekDayLarge(self):
494 84
        self.assertEqual(list(rrule(MONTHLY,
495
                              count=3,
496
                              bymonth=(1, 3),
497
                              byweekday=(TU(3), TH(-3)),
498
                              dtstart=datetime(1997, 9, 2, 9, 0))),
499
                         [datetime(1998, 1, 15, 9, 0),
500
                          datetime(1998, 1, 20, 9, 0),
501
                          datetime(1998, 3, 12, 9, 0)])
502

503 84
    def testMonthlyByMonthDayAndWeekDay(self):
504 84
        self.assertEqual(list(rrule(MONTHLY,
505
                              count=3,
506
                              bymonthday=(1, 3),
507
                              byweekday=(TU, TH),
508
                              dtstart=datetime(1997, 9, 2, 9, 0))),
509
                         [datetime(1998, 1, 1, 9, 0),
510
                          datetime(1998, 2, 3, 9, 0),
511
                          datetime(1998, 3, 3, 9, 0)])
512

513 84
    def testMonthlyByMonthAndMonthDayAndWeekDay(self):
514 84
        self.assertEqual(list(rrule(MONTHLY,
515
                              count=3,
516
                              bymonth=(1, 3),
517
                              bymonthday=(1, 3),
518
                              byweekday=(TU, TH),
519
                              dtstart=datetime(1997, 9, 2, 9, 0))),
520
                         [datetime(1998, 1, 1, 9, 0),
521
                          datetime(1998, 3, 3, 9, 0),
522
                          datetime(2001, 3, 1, 9, 0)])
523

524 84
    def testMonthlyByYearDay(self):
525 84
        self.assertEqual(list(rrule(MONTHLY,
526
                              count=4,
527
                              byyearday=(1, 100, 200, 365),
528
                              dtstart=datetime(1997, 9, 2, 9, 0))),
529
                         [datetime(1997, 12, 31, 9, 0),
530
                          datetime(1998, 1, 1, 9, 0),
531
                          datetime(1998, 4, 10, 9, 0),
532
                          datetime(1998, 7, 19, 9, 0)])
533

534 84
    def testMonthlyByYearDayNeg(self):
535 84
        self.assertEqual(list(rrule(MONTHLY,
536
                              count=4,
537
                              byyearday=(-365, -266, -166, -1),
538
                              dtstart=datetime(1997, 9, 2, 9, 0))),
539
                         [datetime(1997, 12, 31, 9, 0),
540
                          datetime(1998, 1, 1, 9, 0),
541
                          datetime(1998, 4, 10, 9, 0),
542
                          datetime(1998, 7, 19, 9, 0)])
543

544 84
    def testMonthlyByMonthAndYearDay(self):
545 84
        self.assertEqual(list(rrule(MONTHLY,
546
                              count=4,
547
                              bymonth=(4, 7),
548
                              byyearday=(1, 100, 200, 365),
549
                              dtstart=datetime(1997, 9, 2, 9, 0))),
550
                         [datetime(1998, 4, 10, 9, 0),
551
                          datetime(1998, 7, 19, 9, 0),
552
                          datetime(1999, 4, 10, 9, 0),
553
                          datetime(1999, 7, 19, 9, 0)])
554

555 84
    def testMonthlyByMonthAndYearDayNeg(self):
556 84
        self.assertEqual(list(rrule(MONTHLY,
557
                              count=4,
558
                              bymonth=(4, 7),
559
                              byyearday=(-365, -266, -166, -1),
560
                              dtstart=datetime(1997, 9, 2, 9, 0))),
561
                         [datetime(1998, 4, 10, 9, 0),
562
                          datetime(1998, 7, 19, 9, 0),
563
                          datetime(1999, 4, 10, 9, 0),
564
                          datetime(1999, 7, 19, 9, 0)])
565

566 84
    def testMonthlyByWeekNo(self):
567 84
        self.assertEqual(list(rrule(MONTHLY,
568
                              count=3,
569
                              byweekno=20,
570
                              dtstart=datetime(1997, 9, 2, 9, 0))),
571
                         [datetime(1998, 5, 11, 9, 0),
572
                          datetime(1998, 5, 12, 9, 0),
573
                          datetime(1998, 5, 13, 9, 0)])
574

575 84
    def testMonthlyByWeekNoAndWeekDay(self):
576
        # That's a nice one. The first days of week number one
577
        # may be in the last year.
578 84
        self.assertEqual(list(rrule(MONTHLY,
579
                              count=3,
580
                              byweekno=1,
581
                              byweekday=MO,
582
                              dtstart=datetime(1997, 9, 2, 9, 0))),
583
                         [datetime(1997, 12, 29, 9, 0),
584
                          datetime(1999, 1, 4, 9, 0),
585
                          datetime(2000, 1, 3, 9, 0)])
586

587 84
    def testMonthlyByWeekNoAndWeekDayLarge(self):
588
        # Another nice test. The last days of week number 52/53
589
        # may be in the next year.
590 84
        self.assertEqual(list(rrule(MONTHLY,
591
                              count=3,
592
                              byweekno=52,
593
                              byweekday=SU,
594
                              dtstart=datetime(1997, 9, 2, 9, 0))),
595
                         [datetime(1997, 12, 28, 9, 0),
596
                          datetime(1998, 12, 27, 9, 0),
597
                          datetime(2000, 1, 2, 9, 0)])
598

599 84
    def testMonthlyByWeekNoAndWeekDayLast(self):
600 84
        self.assertEqual(list(rrule(MONTHLY,
601
                              count=3,
602
                              byweekno=-1,
603
                              byweekday=SU,
604
                              dtstart=datetime(1997, 9, 2, 9, 0))),
605
                         [datetime(1997, 12, 28, 9, 0),
606
                          datetime(1999, 1, 3, 9, 0),
607
                          datetime(2000, 1, 2, 9, 0)])
608

609 84
    def testMonthlyByWeekNoAndWeekDay53(self):
610 84
        self.assertEqual(list(rrule(MONTHLY,
611
                              count=3,
612
                              byweekno=53,
613
                              byweekday=MO,
614
                              dtstart=datetime(1997, 9, 2, 9, 0))),
615
                         [datetime(1998, 12, 28, 9, 0),
616
                          datetime(2004, 12, 27, 9, 0),
617
                          datetime(2009, 12, 28, 9, 0)])
618

619 84
    def testMonthlyByEaster(self):
620 84
        self.assertEqual(list(rrule(MONTHLY,
621
                              count=3,
622
                              byeaster=0,
623
                              dtstart=datetime(1997, 9, 2, 9, 0))),
624
                         [datetime(1998, 4, 12, 9, 0),
625
                          datetime(1999, 4, 4, 9, 0),
626
                          datetime(2000, 4, 23, 9, 0)])
627

628 84
    def testMonthlyByEasterPos(self):
629 84
        self.assertEqual(list(rrule(MONTHLY,
630
                              count=3,
631
                              byeaster=1,
632
                              dtstart=datetime(1997, 9, 2, 9, 0))),
633
                         [datetime(1998, 4, 13, 9, 0),
634
                          datetime(1999, 4, 5, 9, 0),
635
                          datetime(2000, 4, 24, 9, 0)])
636

637 84
    def testMonthlyByEasterNeg(self):
638 84
        self.assertEqual(list(rrule(MONTHLY,
639
                              count=3,
640
                              byeaster=-1,
641
                              dtstart=datetime(1997, 9, 2, 9, 0))),
642
                         [datetime(1998, 4, 11, 9, 0),
643
                          datetime(1999, 4, 3, 9, 0),
644
                          datetime(2000, 4, 22, 9, 0)])
645

646 84
    def testMonthlyByHour(self):
647 84
        self.assertEqual(list(rrule(MONTHLY,
648
                              count=3,
649
                              byhour=(6, 18),
650
                              dtstart=datetime(1997, 9, 2, 9, 0))),
651
                         [datetime(1997, 9, 2, 18, 0),
652
                          datetime(1997, 10, 2, 6, 0),
653
                          datetime(1997, 10, 2, 18, 0)])
654

655 84
    def testMonthlyByMinute(self):
656 84
        self.assertEqual(list(rrule(MONTHLY,
657
                              count=3,
658
                              byminute=(6, 18),
659
                              dtstart=datetime(1997, 9, 2, 9, 0))),
660
                         [datetime(1997, 9, 2, 9, 6),
661
                          datetime(1997, 9, 2, 9, 18),
662
                          datetime(1997, 10, 2, 9, 6)])
663

664 84
    def testMonthlyBySecond(self):
665 84
        self.assertEqual(list(rrule(MONTHLY,
666
                              count=3,
667
                              bysecond=(6, 18),
668
                              dtstart=datetime(1997, 9, 2, 9, 0))),
669
                         [datetime(1997, 9, 2, 9, 0, 6),
670
                          datetime(1997, 9, 2, 9, 0, 18),
671
                          datetime(1997, 10, 2, 9, 0, 6)])
672

673 84
    def testMonthlyByHourAndMinute(self):
674 84
        self.assertEqual(list(rrule(MONTHLY,
675
                              count=3,
676
                              byhour=(6, 18),
677
                              byminute=(6, 18),
678
                              dtstart=datetime(1997, 9, 2, 9, 0))),
679
                         [datetime(1997, 9, 2, 18, 6),
680
                          datetime(1997, 9, 2, 18, 18),
681
                          datetime(1997, 10, 2, 6, 6)])
682

683 84
    def testMonthlyByHourAndSecond(self):
684 84
        self.assertEqual(list(rrule(MONTHLY,
685
                              count=3,
686
                              byhour=(6, 18),
687
                              bysecond=(6, 18),
688
                              dtstart=datetime(1997, 9, 2, 9, 0))),
689
                         [datetime(1997, 9, 2, 18, 0, 6),
690
                          datetime(1997, 9, 2, 18, 0, 18),
691
                          datetime(1997, 10, 2, 6, 0, 6)])
692

693 84
    def testMonthlyByMinuteAndSecond(self):
694 84
        self.assertEqual(list(rrule(MONTHLY,
695
                              count=3,
696
                              byminute=(6, 18),
697
                              bysecond=(6, 18),
698
                              dtstart=datetime(1997, 9, 2, 9, 0))),
699
                         [datetime(1997, 9, 2, 9, 6, 6),
700
                          datetime(1997, 9, 2, 9, 6, 18),
701
                          datetime(1997, 9, 2, 9, 18, 6)])
702

703 84
    def testMonthlyByHourAndMinuteAndSecond(self):
704 84
        self.assertEqual(list(rrule(MONTHLY,
705
                              count=3,
706
                              byhour=(6, 18),
707
                              byminute=(6, 18),
708
                              bysecond=(6, 18),
709
                              dtstart=datetime(1997, 9, 2, 9, 0))),
710
                         [datetime(1997, 9, 2, 18, 6, 6),
711
                          datetime(1997, 9, 2, 18, 6, 18),
712
                          datetime(1997, 9, 2, 18, 18, 6)])
713

714 84
    def testMonthlyBySetPos(self):
715 84
        self.assertEqual(list(rrule(MONTHLY,
716
                              count=3,
717
                              bymonthday=(13, 17),
718
                              byhour=(6, 18),
719
                              bysetpos=(3, -3),
720
                              dtstart=datetime(1997, 9, 2, 9, 0))),
721
                         [datetime(1997, 9, 13, 18, 0),
722
                          datetime(1997, 9, 17, 6, 0),
723
                          datetime(1997, 10, 13, 18, 0)])
724

725 84
    def testWeekly(self):
726 84
        self.assertEqual(list(rrule(WEEKLY,
727
                              count=3,
728
                              dtstart=datetime(1997, 9, 2, 9, 0))),
729
                         [datetime(1997, 9, 2, 9, 0),
730
                          datetime(1997, 9, 9, 9, 0),
731
                          datetime(1997, 9, 16, 9, 0)])
732

733 84
    def testWeeklyInterval(self):
734 84
        self.assertEqual(list(rrule(WEEKLY,
735
                              count=3,
736
                              interval=2,
737
                              dtstart=datetime(1997, 9, 2, 9, 0))),
738
                         [datetime(1997, 9, 2, 9, 0),
739
                          datetime(1997, 9, 16, 9, 0),
740
                          datetime(1997, 9, 30, 9, 0)])
741

742 84
    def testWeeklyIntervalLarge(self):
743 84
        self.assertEqual(list(rrule(WEEKLY,
744
                              count=3,
745
                              interval=20,
746
                              dtstart=datetime(1997, 9, 2, 9, 0))),
747
                         [datetime(1997, 9, 2, 9, 0),
748
                          datetime(1998, 1, 20, 9, 0),
749
                          datetime(1998, 6, 9, 9, 0)])
750

751 84
    def testWeeklyByMonth(self):
752 84
        self.assertEqual(list(rrule(WEEKLY,
753
                              count=3,
754
                              bymonth=(1, 3),
755
                              dtstart=datetime(1997, 9, 2, 9, 0))),
756
                         [datetime(1998, 1, 6, 9, 0),
757
                          datetime(1998, 1, 13, 9, 0),
758
                          datetime(1998, 1, 20, 9, 0)])
759

760 84
    def testWeeklyByMonthDay(self):
761 84
        self.assertEqual(list(rrule(WEEKLY,
762
                              count=3,
763
                              bymonthday=(1, 3),
764
                              dtstart=datetime(1997, 9, 2, 9, 0))),
765
                         [datetime(1997, 9, 3, 9, 0),
766
                          datetime(1997, 10, 1, 9, 0),
767
                          datetime(1997, 10, 3, 9, 0)])
768

769 84
    def testWeeklyByMonthAndMonthDay(self):
770 84
        self.assertEqual(list(rrule(WEEKLY,
771
                              count=3,
772
                              bymonth=(1, 3),
773
                              bymonthday=(5, 7),
774
                              dtstart=datetime(1997, 9, 2, 9, 0))),
775
                         [datetime(1998, 1, 5, 9, 0),
776
                          datetime(1998, 1, 7, 9, 0),
777
                          datetime(1998, 3, 5, 9, 0)])
778

779 84
    def testWeeklyByWeekDay(self):
780 84
        self.assertEqual(list(rrule(WEEKLY,
781
                              count=3,
782
                              byweekday=(TU, TH),
783
                              dtstart=datetime(1997, 9, 2, 9, 0))),
784
                         [datetime(1997, 9, 2, 9, 0),
785
                          datetime(1997, 9, 4, 9, 0),
786
                          datetime(1997, 9, 9, 9, 0)])
787

788 84
    def testWeeklyByNWeekDay(self):
789 84
        self.assertEqual(list(rrule(WEEKLY,
790
                              count=3,
791
                              byweekday=(TU(1), TH(-1)),
792
                              dtstart=datetime(1997, 9, 2, 9, 0))),
793
                         [datetime(1997, 9, 2, 9, 0),
794
                          datetime(1997, 9, 4, 9, 0),
795
                          datetime(1997, 9, 9, 9, 0)])
796

797 84
    def testWeeklyByMonthAndWeekDay(self):
798
        # This test is interesting, because it crosses the year
799
        # boundary in a weekly period to find day '1' as a
800
        # valid recurrence.
801 84
        self.assertEqual(list(rrule(WEEKLY,
802
                              count=3,
803
                              bymonth=(1, 3),
804
                              byweekday=(TU, TH),
805
                              dtstart=datetime(1997, 9, 2, 9, 0))),
806
                         [datetime(1998, 1, 1, 9, 0),
807
                          datetime(1998, 1, 6, 9, 0),
808
                          datetime(1998, 1, 8, 9, 0)])
809

810 84
    def testWeeklyByMonthAndNWeekDay(self):
811 84
        self.assertEqual(list(rrule(WEEKLY,
812
                              count=3,
813
                              bymonth=(1, 3),
814
                              byweekday=(TU(1), TH(-1)),
815
                              dtstart=datetime(1997, 9, 2, 9, 0))),
816
                         [datetime(1998, 1, 1, 9, 0),
817
                          datetime(1998, 1, 6, 9, 0),
818
                          datetime(1998, 1, 8, 9, 0)])
819

820 84
    def testWeeklyByMonthDayAndWeekDay(self):
821 84
        self.assertEqual(list(rrule(WEEKLY,
822
                              count=3,
823
                              bymonthday=(1, 3),
824
                              byweekday=(TU, TH),
825
                              dtstart=datetime(1997, 9, 2, 9, 0))),
826
                         [datetime(1998, 1, 1, 9, 0),
827
                          datetime(1998, 2, 3, 9, 0),
828
                          datetime(1998, 3, 3, 9, 0)])
829

830 84
    def testWeeklyByMonthAndMonthDayAndWeekDay(self):
831 84
        self.assertEqual(list(rrule(WEEKLY,
832
                              count=3,
833
                              bymonth=(1, 3),
834
                              bymonthday=(1, 3),
835
                              byweekday=(TU, TH),
836
                              dtstart=datetime(1997, 9, 2, 9, 0))),
837
                         [datetime(1998, 1, 1, 9, 0),
838
                          datetime(1998, 3, 3, 9, 0),
839
                          datetime(2001, 3, 1, 9, 0)])
840

841 84
    def testWeeklyByYearDay(self):
842 84
        self.assertEqual(list(rrule(WEEKLY,
843
                              count=4,
844
                              byyearday=(1, 100, 200, 365),
845
                              dtstart=datetime(1997, 9, 2, 9, 0))),
846
                         [datetime(1997, 12, 31, 9, 0),
847
                          datetime(1998, 1, 1, 9, 0),
848
                          datetime(1998, 4, 10, 9, 0),
849
                          datetime(1998, 7, 19, 9, 0)])
850

851 84
    def testWeeklyByYearDayNeg(self):
852 84
        self.assertEqual(list(rrule(WEEKLY,
853
                              count=4,
854
                              byyearday=(-365, -266, -166, -1),
855
                              dtstart=datetime(1997, 9, 2, 9, 0))),
856
                         [datetime(1997, 12, 31, 9, 0),
857
                          datetime(1998, 1, 1, 9, 0),
858
                          datetime(1998, 4, 10, 9, 0),
859
                          datetime(1998, 7, 19, 9, 0)])
860

861 84
    def testWeeklyByMonthAndYearDay(self):
862 84
        self.assertEqual(list(rrule(WEEKLY,
863
                              count=4,
864
                              bymonth=(1, 7),
865
                              byyearday=(1, 100, 200, 365),
866
                              dtstart=datetime(1997, 9, 2, 9, 0))),
867
                         [datetime(1998, 1, 1, 9, 0),
868
                          datetime(1998, 7, 19, 9, 0),
869
                          datetime(1999, 1, 1, 9, 0),
870
                          datetime(1999, 7, 19, 9, 0)])
871

872 84
    def testWeeklyByMonthAndYearDayNeg(self):
873 84
        self.assertEqual(list(rrule(WEEKLY,
874
                              count=4,
875
                              bymonth=(1, 7),
876
                              byyearday=(-365, -266, -166, -1),
877
                              dtstart=datetime(1997, 9, 2, 9, 0))),
878
                         [datetime(1998, 1, 1, 9, 0),
879
                          datetime(1998, 7, 19, 9, 0),
880
                          datetime(1999, 1, 1, 9, 0),
881
                          datetime(1999, 7, 19, 9, 0)])
882

883 84
    def testWeeklyByWeekNo(self):
884 84
        self.assertEqual(list(rrule(WEEKLY,
885
                              count=3,
886
                              byweekno=20,
887
                              dtstart=datetime(1997, 9, 2, 9, 0))),
888
                         [datetime(1998, 5, 11, 9, 0),
889
                          datetime(1998, 5, 12, 9, 0),
890
                          datetime(1998, 5, 13, 9, 0)])
891

892 84
    def testWeeklyByWeekNoAndWeekDay(self):
893
        # That's a nice one. The first days of week number one
894
        # may be in the last year.
895 84
        self.assertEqual(list(rrule(WEEKLY,
896
                              count=3,
897
                              byweekno=1,
898
                              byweekday=MO,
899
                              dtstart=datetime(1997, 9, 2, 9, 0))),
900
                         [datetime(1997, 12, 29, 9, 0),
901
                          datetime(1999, 1, 4, 9, 0),
902
                          datetime(2000, 1, 3, 9, 0)])
903

904 84
    def testWeeklyByWeekNoAndWeekDayLarge(self):
905
        # Another nice test. The last days of week number 52/53
906
        # may be in the next year.
907 84
        self.assertEqual(list(rrule(WEEKLY,
908
                              count=3,
909
                              byweekno=52,
910
                              byweekday=SU,
911
                              dtstart=datetime(1997, 9, 2, 9, 0))),
912
                         [datetime(1997, 12, 28, 9, 0),
913
                          datetime(1998, 12, 27, 9, 0),
914
                          datetime(2000, 1, 2, 9, 0)])
915

916 84
    def testWeeklyByWeekNoAndWeekDayLast(self):
917 84
        self.assertEqual(list(rrule(WEEKLY,
918
                              count=3,
919
                              byweekno=-1,
920
                              byweekday=SU,
921
                              dtstart=datetime(1997, 9, 2, 9, 0))),
922
                         [datetime(1997, 12, 28, 9, 0),
923
                          datetime(1999, 1, 3, 9, 0),
924
                          datetime(2000, 1, 2, 9, 0)])
925

926 84
    def testWeeklyByWeekNoAndWeekDay53(self):
927 84
        self.assertEqual(list(rrule(WEEKLY,
928
                              count=3,
929
                              byweekno=53,
930
                              byweekday=MO,
931
                              dtstart=datetime(1997, 9, 2, 9, 0))),
932
                         [datetime(1998, 12, 28, 9, 0),
933
                          datetime(2004, 12, 27, 9, 0),
934
                          datetime(2009, 12, 28, 9, 0)])
935

936 84
    def testWeeklyByEaster(self):
937 84
        self.assertEqual(list(rrule(WEEKLY,
938
                              count=3,
939
                              byeaster=0,
940
                              dtstart=datetime(1997, 9, 2, 9, 0))),
941
                         [datetime(1998, 4, 12, 9, 0),
942
                          datetime(1999, 4, 4, 9, 0),
943
                          datetime(2000, 4, 23, 9, 0)])
944

945 84
    def testWeeklyByEasterPos(self):
946 84
        self.assertEqual(list(rrule(WEEKLY,
947
                              count=3,
948
                              byeaster=1,
949
                              dtstart=datetime(1997, 9, 2, 9, 0))),
950
                         [datetime(1998, 4, 13, 9, 0),
951
                          datetime(1999, 4, 5, 9, 0),
952
                          datetime(2000, 4, 24, 9, 0)])
953

954 84
    def testWeeklyByEasterNeg(self):
955 84
        self.assertEqual(list(rrule(WEEKLY,
956
                              count=3,
957
                              byeaster=-1,
958
                              dtstart=datetime(1997, 9, 2, 9, 0))),
959
                         [datetime(1998, 4, 11, 9, 0),
960
                          datetime(1999, 4, 3, 9, 0),
961
                          datetime(2000, 4, 22, 9, 0)])
962

963 84
    def testWeeklyByHour(self):
964 84
        self.assertEqual(list(rrule(WEEKLY,
965
                              count=3,
966
                              byhour=(6, 18),
967
                              dtstart=datetime(1997, 9, 2, 9, 0))),
968
                         [datetime(1997, 9, 2, 18, 0),
969
                          datetime(1997, 9, 9, 6, 0),
970
                          datetime(1997, 9, 9, 18, 0)])
971

972 84
    def testWeeklyByMinute(self):
973 84
        self.assertEqual(list(rrule(WEEKLY,
974
                              count=3,
975
                              byminute=(6, 18),
976
                              dtstart=datetime(1997, 9, 2, 9, 0))),
977
                         [datetime(1997, 9, 2, 9, 6),
978
                          datetime(1997, 9, 2, 9, 18),
979
                          datetime(1997, 9, 9, 9, 6)])
980

981 84
    def testWeeklyBySecond(self):
982 84
        self.assertEqual(list(rrule(WEEKLY,
983
                              count=3,
984
                              bysecond=(6, 18),
985
                              dtstart=datetime(1997, 9, 2, 9, 0))),
986
                         [datetime(1997, 9, 2, 9, 0, 6),
987
                          datetime(1997, 9, 2, 9, 0, 18),
988
                          datetime(1997, 9, 9, 9, 0, 6)])
989

990 84
    def testWeeklyByHourAndMinute(self):
991 84
        self.assertEqual(list(rrule(WEEKLY,
992
                              count=3,
993
                              byhour=(6, 18),
994
                              byminute=(6, 18),
995
                              dtstart=datetime(1997, 9, 2, 9, 0))),
996
                         [datetime(1997, 9, 2, 18, 6),
997
                          datetime(1997, 9, 2, 18, 18),
998
                          datetime(1997, 9, 9, 6, 6)])
999

1000 84
    def testWeeklyByHourAndSecond(self):
1001 84
        self.assertEqual(list(rrule(WEEKLY,
1002
                              count=3,
1003
                              byhour=(6, 18),
1004
                              bysecond=(6, 18),
1005
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1006
                         [datetime(1997, 9, 2, 18, 0, 6),
1007
                          datetime(1997, 9, 2, 18, 0, 18),
1008
                          datetime(1997, 9, 9, 6, 0, 6)])
1009

1010 84
    def testWeeklyByMinuteAndSecond(self):
1011 84
        self.assertEqual(list(rrule(WEEKLY,
1012
                              count=3,
1013
                              byminute=(6, 18),
1014
                              bysecond=(6, 18),
1015
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1016
                         [datetime(1997, 9, 2, 9, 6, 6),
1017
                          datetime(1997, 9, 2, 9, 6, 18),
1018
                          datetime(1997, 9, 2, 9, 18, 6)])
1019

1020 84
    def testWeeklyByHourAndMinuteAndSecond(self):
1021 84
        self.assertEqual(list(rrule(WEEKLY,
1022
                              count=3,
1023
                              byhour=(6, 18),
1024
                              byminute=(6, 18),
1025
                              bysecond=(6, 18),
1026
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1027
                         [datetime(1997, 9, 2, 18, 6, 6),
1028
                          datetime(1997, 9, 2, 18, 6, 18),
1029
                          datetime(1997, 9, 2, 18, 18, 6)])
1030

1031 84
    def testWeeklyBySetPos(self):
1032 84
        self.assertEqual(list(rrule(WEEKLY,
1033
                              count=3,
1034
                              byweekday=(TU, TH),
1035
                              byhour=(6, 18),
1036
                              bysetpos=(3, -3),
1037
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1038
                         [datetime(1997, 9, 2, 18, 0),
1039
                          datetime(1997, 9, 4, 6, 0),
1040
                          datetime(1997, 9, 9, 18, 0)])
1041

1042 84
    def testDaily(self):
1043 84
        self.assertEqual(list(rrule(DAILY,
1044
                              count=3,
1045
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1046
                         [datetime(1997, 9, 2, 9, 0),
1047
                          datetime(1997, 9, 3, 9, 0),
1048
                          datetime(1997, 9, 4, 9, 0)])
1049

1050 84
    def testDailyInterval(self):
1051 84
        self.assertEqual(list(rrule(DAILY,
1052
                              count=3,
1053
                              interval=2,
1054
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1055
                         [datetime(1997, 9, 2, 9, 0),
1056
                          datetime(1997, 9, 4, 9, 0),
1057
                          datetime(1997, 9, 6, 9, 0)])
1058

1059 84
    def testDailyIntervalLarge(self):
1060 84
        self.assertEqual(list(rrule(DAILY,
1061
                              count=3,
1062
                              interval=92,
1063
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1064
                         [datetime(1997, 9, 2, 9, 0),
1065
                          datetime(1997, 12, 3, 9, 0),
1066
                          datetime(1998, 3, 5, 9, 0)])
1067

1068 84
    def testDailyByMonth(self):
1069 84
        self.assertEqual(list(rrule(DAILY,
1070
                              count=3,
1071
                              bymonth=(1, 3),
1072
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1073
                         [datetime(1998, 1, 1, 9, 0),
1074
                          datetime(1998, 1, 2, 9, 0),
1075
                          datetime(1998, 1, 3, 9, 0)])
1076

1077 84
    def testDailyByMonthDay(self):
1078 84
        self.assertEqual(list(rrule(DAILY,
1079
                              count=3,
1080
                              bymonthday=(1, 3),
1081
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1082
                         [datetime(1997, 9, 3, 9, 0),
1083
                          datetime(1997, 10, 1, 9, 0),
1084
                          datetime(1997, 10, 3, 9, 0)])
1085

1086 84
    def testDailyByMonthAndMonthDay(self):
1087 84
        self.assertEqual(list(rrule(DAILY,
1088
                              count=3,
1089
                              bymonth=(1, 3),
1090
                              bymonthday=(5, 7),
1091
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1092
                         [datetime(1998, 1, 5, 9, 0),
1093
                          datetime(1998, 1, 7, 9, 0),
1094
                          datetime(1998, 3, 5, 9, 0)])
1095

1096 84
    def testDailyByWeekDay(self):
1097 84
        self.assertEqual(list(rrule(DAILY,
1098
                              count=3,
1099
                              byweekday=(TU, TH),
1100
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1101
                         [datetime(1997, 9, 2, 9, 0),
1102
                          datetime(1997, 9, 4, 9, 0),
1103
                          datetime(1997, 9, 9, 9, 0)])
1104

1105 84
    def testDailyByNWeekDay(self):
1106 84
        self.assertEqual(list(rrule(DAILY,
1107
                              count=3,
1108
                              byweekday=(TU(1), TH(-1)),
1109
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1110
                         [datetime(1997, 9, 2, 9, 0),
1111
                          datetime(1997, 9, 4, 9, 0),
1112
                          datetime(1997, 9, 9, 9, 0)])
1113

1114 84
    def testDailyByMonthAndWeekDay(self):
1115 84
        self.assertEqual(list(rrule(DAILY,
1116
                              count=3,
1117
                              bymonth=(1, 3),
1118
                              byweekday=(TU, TH),
1119
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1120
                         [datetime(1998, 1, 1, 9, 0),
1121
                          datetime(1998, 1, 6, 9, 0),
1122
                          datetime(1998, 1, 8, 9, 0)])
1123

1124 84
    def testDailyByMonthAndNWeekDay(self):
1125 84
        self.assertEqual(list(rrule(DAILY,
1126
                              count=3,
1127
                              bymonth=(1, 3),
1128
                              byweekday=(TU(1), TH(-1)),
1129
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1130
                         [datetime(1998, 1, 1, 9, 0),
1131
                          datetime(1998, 1, 6, 9, 0),
1132
                          datetime(1998, 1, 8, 9, 0)])
1133

1134 84
    def testDailyByMonthDayAndWeekDay(self):
1135 84
        self.assertEqual(list(rrule(DAILY,
1136
                              count=3,
1137
                              bymonthday=(1, 3),
1138
                              byweekday=(TU, TH),
1139
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1140
                         [datetime(1998, 1, 1, 9, 0),
1141
                          datetime(1998, 2, 3, 9, 0),
1142
                          datetime(1998, 3, 3, 9, 0)])
1143

1144 84
    def testDailyByMonthAndMonthDayAndWeekDay(self):
1145 84
        self.assertEqual(list(rrule(DAILY,
1146
                              count=3,
1147
                              bymonth=(1, 3),
1148
                              bymonthday=(1, 3),
1149
                              byweekday=(TU, TH),
1150
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1151
                         [datetime(1998, 1, 1, 9, 0),
1152
                          datetime(1998, 3, 3, 9, 0),
1153
                          datetime(2001, 3, 1, 9, 0)])
1154

1155 84
    def testDailyByYearDay(self):
1156 84
        self.assertEqual(list(rrule(DAILY,
1157
                              count=4,
1158
                              byyearday=(1, 100, 200, 365),
1159
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1160
                         [datetime(1997, 12, 31, 9, 0),
1161
                          datetime(1998, 1, 1, 9, 0),
1162
                          datetime(1998, 4, 10, 9, 0),
1163
                          datetime(1998, 7, 19, 9, 0)])
1164

1165 84
    def testDailyByYearDayNeg(self):
1166 84
        self.assertEqual(list(rrule(DAILY,
1167
                              count=4,
1168
                              byyearday=(-365, -266, -166, -1),
1169
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1170
                         [datetime(1997, 12, 31, 9, 0),
1171
                          datetime(1998, 1, 1, 9, 0),
1172
                          datetime(1998, 4, 10, 9, 0),
1173
                          datetime(1998, 7, 19, 9, 0)])
1174

1175 84
    def testDailyByMonthAndYearDay(self):
1176 84
        self.assertEqual(list(rrule(DAILY,
1177
                              count=4,
1178
                              bymonth=(1, 7),
1179
                              byyearday=(1, 100, 200, 365),
1180
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1181
                         [datetime(1998, 1, 1, 9, 0),
1182
                          datetime(1998, 7, 19, 9, 0),
1183
                          datetime(1999, 1, 1, 9, 0),
1184
                          datetime(1999, 7, 19, 9, 0)])
1185

1186 84
    def testDailyByMonthAndYearDayNeg(self):
1187 84
        self.assertEqual(list(rrule(DAILY,
1188
                              count=4,
1189
                              bymonth=(1, 7),
1190
                              byyearday=(-365, -266, -166, -1),
1191
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1192
                         [datetime(1998, 1, 1, 9, 0),
1193
                          datetime(1998, 7, 19, 9, 0),
1194
                          datetime(1999, 1, 1, 9, 0),
1195
                          datetime(1999, 7, 19, 9, 0)])
1196

1197 84
    def testDailyByWeekNo(self):
1198 84
        self.assertEqual(list(rrule(DAILY,
1199
                              count=3,
1200
                              byweekno=20,
1201
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1202
                         [datetime(1998, 5, 11, 9, 0),
1203
                          datetime(1998, 5, 12, 9, 0),
1204
                          datetime(1998, 5, 13, 9, 0)])
1205

1206 84
    def testDailyByWeekNoAndWeekDay(self):
1207
        # That's a nice one. The first days of week number one
1208
        # may be in the last year.
1209 84
        self.assertEqual(list(rrule(DAILY,
1210
                              count=3,
1211
                              byweekno=1,
1212
                              byweekday=MO,
1213
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1214
                         [datetime(1997, 12, 29, 9, 0),
1215
                          datetime(1999, 1, 4, 9, 0),
1216
                          datetime(2000, 1, 3, 9, 0)])
1217

1218 84
    def testDailyByWeekNoAndWeekDayLarge(self):
1219
        # Another nice test. The last days of week number 52/53
1220
        # may be in the next year.
1221 84
        self.assertEqual(list(rrule(DAILY,
1222
                              count=3,
1223
                              byweekno=52,
1224
                              byweekday=SU,
1225
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1226
                         [datetime(1997, 12, 28, 9, 0),
1227
                          datetime(1998, 12, 27, 9, 0),
1228
                          datetime(2000, 1, 2, 9, 0)])
1229

1230 84
    def testDailyByWeekNoAndWeekDayLast(self):
1231 84
        self.assertEqual(list(rrule(DAILY,
1232
                              count=3,
1233
                              byweekno=-1,
1234
                              byweekday=SU,
1235
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1236
                         [datetime(1997, 12, 28, 9, 0),
1237
                          datetime(1999, 1, 3, 9, 0),
1238
                          datetime(2000, 1, 2, 9, 0)])
1239

1240 84
    def testDailyByWeekNoAndWeekDay53(self):
1241 84
        self.assertEqual(list(rrule(DAILY,
1242
                              count=3,
1243
                              byweekno=53,
1244
                              byweekday=MO,
1245
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1246
                         [datetime(1998, 12, 28, 9, 0),
1247
                          datetime(2004, 12, 27, 9, 0),
1248
                          datetime(2009, 12, 28, 9, 0)])
1249

1250 84
    def testDailyByEaster(self):
1251 84
        self.assertEqual(list(rrule(DAILY,
1252
                              count=3,
1253
                              byeaster=0,
1254
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1255
                         [datetime(1998, 4, 12, 9, 0),
1256
                          datetime(1999, 4, 4, 9, 0),
1257
                          datetime(2000, 4, 23, 9, 0)])
1258

1259 84
    def testDailyByEasterPos(self):
1260 84
        self.assertEqual(list(rrule(DAILY,
1261
                              count=3,
1262
                              byeaster=1,
1263
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1264
                         [datetime(1998, 4, 13, 9, 0),
1265
                          datetime(1999, 4, 5, 9, 0),
1266
                          datetime(2000, 4, 24, 9, 0)])
1267

1268 84
    def testDailyByEasterNeg(self):
1269 84
        self.assertEqual(list(rrule(DAILY,
1270
                              count=3,
1271
                              byeaster=-1,
1272
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1273
                         [datetime(1998, 4, 11, 9, 0),
1274
                          datetime(1999, 4, 3, 9, 0),
1275
                          datetime(2000, 4, 22, 9, 0)])
1276

1277 84
    def testDailyByHour(self):
1278 84
        self.assertEqual(list(rrule(DAILY,
1279
                              count=3,
1280
                              byhour=(6, 18),
1281
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1282
                         [datetime(1997, 9, 2, 18, 0),
1283
                          datetime(1997, 9, 3, 6, 0),
1284
                          datetime(1997, 9, 3, 18, 0)])
1285

1286 84
    def testDailyByMinute(self):
1287 84
        self.assertEqual(list(rrule(DAILY,
1288
                              count=3,
1289
                              byminute=(6, 18),
1290
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1291
                         [datetime(1997, 9, 2, 9, 6),
1292
                          datetime(1997, 9, 2, 9, 18),
1293
                          datetime(1997, 9, 3, 9, 6)])
1294

1295 84
    def testDailyBySecond(self):
1296 84
        self.assertEqual(list(rrule(DAILY,
1297
                              count=3,
1298
                              bysecond=(6, 18),
1299
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1300
                         [datetime(1997, 9, 2, 9, 0, 6),
1301
                          datetime(1997, 9, 2, 9, 0, 18),
1302
                          datetime(1997, 9, 3, 9, 0, 6)])
1303

1304 84
    def testDailyByHourAndMinute(self):
1305 84
        self.assertEqual(list(rrule(DAILY,
1306
                              count=3,
1307
                              byhour=(6, 18),
1308
                              byminute=(6, 18),
1309
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1310
                         [datetime(1997, 9, 2, 18, 6),
1311
                          datetime(1997, 9, 2, 18, 18),
1312
                          datetime(1997, 9, 3, 6, 6)])
1313

1314 84
    def testDailyByHourAndSecond(self):
1315 84
        self.assertEqual(list(rrule(DAILY,
1316
                              count=3,
1317
                              byhour=(6, 18),
1318
                              bysecond=(6, 18),
1319
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1320
                         [datetime(1997, 9, 2, 18, 0, 6),
1321
                          datetime(1997, 9, 2, 18, 0, 18),
1322
                          datetime(1997, 9, 3, 6, 0, 6)])
1323

1324 84
    def testDailyByMinuteAndSecond(self):
1325 84
        self.assertEqual(list(rrule(DAILY,
1326
                              count=3,
1327
                              byminute=(6, 18),
1328
                              bysecond=(6, 18),
1329
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1330
                         [datetime(1997, 9, 2, 9, 6, 6),
1331
                          datetime(1997, 9, 2, 9, 6, 18),
1332
                          datetime(1997, 9, 2, 9, 18, 6)])
1333

1334 84
    def testDailyByHourAndMinuteAndSecond(self):
1335 84
        self.assertEqual(list(rrule(DAILY,
1336
                              count=3,
1337
                              byhour=(6, 18),
1338
                              byminute=(6, 18),
1339
                              bysecond=(6, 18),
1340
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1341
                         [datetime(1997, 9, 2, 18, 6, 6),
1342
                          datetime(1997, 9, 2, 18, 6, 18),
1343
                          datetime(1997, 9, 2, 18, 18, 6)])
1344

1345 84
    def testDailyBySetPos(self):
1346 84
        self.assertEqual(list(rrule(DAILY,
1347
                              count=3,
1348
                              byhour=(6, 18),
1349
                              byminute=(15, 45),
1350
                              bysetpos=(3, -3),
1351
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1352
                         [datetime(1997, 9, 2, 18, 15),
1353
                          datetime(1997, 9, 3, 6, 45),
1354
                          datetime(1997, 9, 3, 18, 15)])
1355

1356 84
    def testHourly(self):
1357 84
        self.assertEqual(list(rrule(HOURLY,
1358
                              count=3,
1359
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1360
                         [datetime(1997, 9, 2, 9, 0),
1361
                          datetime(1997, 9, 2, 10, 0),
1362
                          datetime(1997, 9, 2, 11, 0)])
1363

1364 84
    def testHourlyInterval(self):
1365 84
        self.assertEqual(list(rrule(HOURLY,
1366
                              count=3,
1367
                              interval=2,
1368
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1369
                         [datetime(1997, 9, 2, 9, 0),
1370
                          datetime(1997, 9, 2, 11, 0),
1371
                          datetime(1997, 9, 2, 13, 0)])
1372

1373 84
    def testHourlyIntervalLarge(self):
1374 84
        self.assertEqual(list(rrule(HOURLY,
1375
                              count=3,
1376
                              interval=769,
1377
                              dtstart=datetime(1997, 9, 2, 9, 0))),
1378
                         [datetime(1997, 9, 2, 9, 0),
1379
                          datetime(1997, 10, 4, 10, 0),
1380
                          datetime(1997, 11, 5, 11, 0)])
1381

1382 84
    def testHourlyByMonth(self):
1383 84
        self.assertEqual(list(rrule(HOURLY,
1384
                              count=3,
1385