~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to fai/python-dateutil-0.4/test.py

  • Committer: Robert Collins
  • Date: 2005-09-14 11:27:20 UTC
  • mto: (147.2.6) (364.1.3 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: robertc@robertcollins.net-20050914112720-c66a21de86eafa6e
trim fai cribbage

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
import unittest
3
 
from cStringIO import StringIO
4
 
import base64
5
 
import os
6
 
 
7
 
# Add build directory to search path
8
 
if os.path.exists("build"):
9
 
        from distutils.util import get_platform
10
 
        import sys
11
 
        s = "build/lib.%s-%.3s" % (get_platform(), sys.version)
12
 
        s = os.path.join(os.getcwd(), s)
13
 
        sys.path.insert(0,s)
14
 
 
15
 
from dateutil.relativedelta import *
16
 
from dateutil.parser import *
17
 
from dateutil.easter import *
18
 
from dateutil.rrule import *
19
 
from dateutil.tz import *
20
 
 
21
 
from datetime import *
22
 
 
23
 
import calendar
24
 
import time
25
 
 
26
 
class RelativeDeltaTest(unittest.TestCase):
27
 
    now = datetime(2003, 9, 17, 20, 54, 47, 282310)
28
 
    today = date(2003, 9, 17)
29
 
 
30
 
    def testNextMonth(self):
31
 
        self.assertEqual(self.now+relativedelta(months=+1),
32
 
                         datetime(2003, 10, 17, 20, 54, 47, 282310))
33
 
 
34
 
    def testNextMonthPlusOneWeek(self):
35
 
        self.assertEqual(self.now+relativedelta(months=+1, weeks=+1),
36
 
                         datetime(2003, 10, 24, 20, 54, 47, 282310))
37
 
    def testNextMonthPlusOneWeek10am(self):
38
 
        self.assertEqual(self.today +
39
 
                         relativedelta(months=+1, weeks=+1, hour=10),
40
 
                         datetime(2003, 10, 24, 10, 0))
41
 
 
42
 
    def testNextMonthPlusOneWeek10amDiff(self):
43
 
        self.assertEqual(relativedelta(datetime(2003, 10, 24, 10, 0),
44
 
                                       self.today),
45
 
                         relativedelta(months=+1, days=+7, hours=+10))
46
 
 
47
 
    def testOneMonthBeforeOneYear(self):
48
 
        self.assertEqual(self.now+relativedelta(years=+1, months=-1),
49
 
                         datetime(2004, 8, 17, 20, 54, 47, 282310))
50
 
 
51
 
    def testMonthsOfDiffNumOfDays(self):
52
 
        self.assertEqual(date(2003, 1, 27)+relativedelta(months=+1),
53
 
                         date(2003, 2, 27))
54
 
        self.assertEqual(date(2003, 1, 31)+relativedelta(months=+1),
55
 
                         date(2003, 2, 28))
56
 
        self.assertEqual(date(2003, 1, 31)+relativedelta(months=+2),
57
 
                         date(2003, 3, 31))
58
 
 
59
 
    def testMonthsOfDiffNumOfDaysWithYears(self):
60
 
        self.assertEqual(date(2000, 2, 28)+relativedelta(years=+1),
61
 
                         date(2001, 2, 28))
62
 
        self.assertEqual(date(2000, 2, 29)+relativedelta(years=+1),
63
 
                         date(2001, 2, 28))
64
 
 
65
 
        self.assertEqual(date(1999, 2, 28)+relativedelta(years=+1),
66
 
                         date(2000, 2, 28))
67
 
        self.assertEqual(date(1999, 3, 1)+relativedelta(years=+1),
68
 
                         date(2000, 3, 1))
69
 
        self.assertEqual(date(1999, 3, 1)+relativedelta(years=+1),
70
 
                         date(2000, 3, 1))
71
 
 
72
 
        self.assertEqual(date(2001, 2, 28)+relativedelta(years=-1),
73
 
                         date(2000, 2, 28))
74
 
        self.assertEqual(date(2001, 3, 1)+relativedelta(years=-1),
75
 
                         date(2000, 3, 1))
76
 
 
77
 
    def testNextFriday(self):
78
 
        self.assertEqual(self.today+relativedelta(weekday=FR),
79
 
                         date(2003, 9, 19))
80
 
 
81
 
    def testNextFridayInt(self):
82
 
        self.assertEqual(self.today+relativedelta(weekday=calendar.FRIDAY),
83
 
                         date(2003, 9, 19))
84
 
 
85
 
    def testLastFridayInThisMonth(self):
86
 
        self.assertEqual(self.today+relativedelta(day=31, weekday=FR(-1)),
87
 
                         date(2003, 9, 26))
88
 
 
89
 
    def testNextWednesdayIsToday(self):
90
 
        self.assertEqual(self.today+relativedelta(weekday=WE),
91
 
                         date(2003, 9, 17))
92
 
 
93
 
 
94
 
    def testNextWenesdayNotToday(self):
95
 
        self.assertEqual(self.today+relativedelta(days=+1, weekday=WE),
96
 
                         date(2003, 9, 24))
97
 
        
98
 
    def test15thISOYearWeek(self):
99
 
        self.assertEqual(date(2003, 1, 1) +
100
 
                         relativedelta(day=4, weeks=+14, weekday=MO(-1)),
101
 
                         date(2003, 4, 7))
102
 
 
103
 
    def testMillenniumAge(self):
104
 
        self.assertEqual(relativedelta(self.now, date(2001,1,1)),
105
 
                         relativedelta(years=+2, months=+8, days=+16,
106
 
                                       hours=+20, minutes=+54, seconds=+47,
107
 
                                       microseconds=+282310))
108
 
 
109
 
    def testJohnAge(self):
110
 
        self.assertEqual(relativedelta(self.now,
111
 
                                       datetime(1978, 4, 5, 12, 0)),
112
 
                         relativedelta(years=+25, months=+5, days=+12,
113
 
                                       hours=+8, minutes=+54, seconds=+47,
114
 
                                       microseconds=+282310))
115
 
 
116
 
    def testJohnAgeWithDate(self):
117
 
        self.assertEqual(relativedelta(self.today,
118
 
                                       datetime(1978, 4, 5, 12, 0)),
119
 
                         relativedelta(years=+25, months=+5, days=+11,
120
 
                                       hours=+12))
121
 
 
122
 
    def testYearDay(self):
123
 
        self.assertEqual(date(2003, 1, 1)+relativedelta(yearday=260),
124
 
                         date(2003, 9, 17))
125
 
        self.assertEqual(date(2002, 1, 1)+relativedelta(yearday=260),
126
 
                         date(2002, 9, 17))
127
 
        self.assertEqual(date(2000, 1, 1)+relativedelta(yearday=260),
128
 
                         date(2000, 9, 16))
129
 
        self.assertEqual(self.today+relativedelta(yearday=261),
130
 
                         date(2003, 9, 18))
131
 
 
132
 
    def testNonLeapYearDay(self):
133
 
        self.assertEqual(date(2003, 1, 1)+relativedelta(nlyearday=260),
134
 
                         date(2003, 9, 17))
135
 
        self.assertEqual(date(2002, 1, 1)+relativedelta(nlyearday=260),
136
 
                         date(2002, 9, 17))
137
 
        self.assertEqual(date(2000, 1, 1)+relativedelta(nlyearday=260),
138
 
                         date(2000, 9, 17))
139
 
        self.assertEqual(self.today+relativedelta(yearday=261),
140
 
                         date(2003, 9, 18))
141
 
 
142
 
class RRuleTest(unittest.TestCase):
143
 
 
144
 
    def testYearly(self):
145
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
146
 
                              count=3,
147
 
                              dtstart=parse("19970902T090000"))),
148
 
                         [datetime(1997, 9, 2, 9, 0),
149
 
                          datetime(1998, 9, 2, 9, 0),
150
 
                          datetime(1999, 9, 2, 9, 0)])
151
 
 
152
 
    def testYearlyInterval(self):
153
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
154
 
                              count=3,
155
 
                              interval=2,
156
 
                              dtstart=parse("19970902T090000"))),
157
 
                         [datetime(1997, 9, 2, 9, 0),
158
 
                          datetime(1999, 9, 2, 9, 0),
159
 
                          datetime(2001, 9, 2, 9, 0)])
160
 
 
161
 
    def testYearlyIntervalLarge(self):
162
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
163
 
                              count=3,
164
 
                              interval=100,
165
 
                              dtstart=parse("19970902T090000"))),
166
 
                         [datetime(1997, 9, 2, 9, 0),
167
 
                          datetime(2097, 9, 2, 9, 0),
168
 
                          datetime(2197, 9, 2, 9, 0)])
169
 
 
170
 
    def testYearlyByMonth(self):
171
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
172
 
                              count=3,
173
 
                              bymonth=(1,3),
174
 
                              dtstart=parse("19970902T090000"))),
175
 
                         [datetime(1998, 1, 2, 9, 0),
176
 
                          datetime(1998, 3, 2, 9, 0),
177
 
                          datetime(1999, 1, 2, 9, 0)])
178
 
 
179
 
    def testYearlyByMonthDay(self):
180
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
181
 
                              count=3,
182
 
                              bymonthday=(1,3),
183
 
                              dtstart=parse("19970902T090000"))),
184
 
                         [datetime(1997, 9, 3, 9, 0),
185
 
                          datetime(1997, 10, 1, 9, 0),
186
 
                          datetime(1997, 10, 3, 9, 0)])
187
 
 
188
 
    def testYearlyByMonthAndMonthDay(self):
189
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
190
 
                              count=3,
191
 
                              bymonth=(1,3),
192
 
                              bymonthday=(5,7),
193
 
                              dtstart=parse("19970902T090000"))),
194
 
                         [datetime(1998, 1, 5, 9, 0),
195
 
                          datetime(1998, 1, 7, 9, 0),
196
 
                          datetime(1998, 3, 5, 9, 0)])
197
 
 
198
 
    def testYearlyByWeekDay(self):
199
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
200
 
                              count=3,
201
 
                              byweekday=(TU,TH),
202
 
                              dtstart=parse("19970902T090000"))),
203
 
                         [datetime(1997, 9, 2, 9, 0),
204
 
                          datetime(1997, 9, 4, 9, 0),
205
 
                          datetime(1997, 9, 9, 9, 0)])
206
 
 
207
 
    def testYearlyByNWeekDay(self):
208
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
209
 
                              count=3,
210
 
                              byweekday=(TU(1),TH(-1)),
211
 
                              dtstart=parse("19970902T090000"))),
212
 
                         [datetime(1997, 12, 25, 9, 0),
213
 
                          datetime(1998, 1, 6, 9, 0),
214
 
                          datetime(1998, 12, 31, 9, 0)])
215
 
 
216
 
    def testYearlyByNWeekDayLarge(self):
217
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
218
 
                              count=3,
219
 
                              byweekday=(TU(3),TH(-3)),
220
 
                              dtstart=parse("19970902T090000"))),
221
 
                         [datetime(1997, 12, 11, 9, 0),
222
 
                          datetime(1998, 1, 20, 9, 0),
223
 
                          datetime(1998, 12, 17, 9, 0)])
224
 
 
225
 
    def testYearlyByMonthAndWeekDay(self):
226
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
227
 
                              count=3,
228
 
                              bymonth=(1,3),
229
 
                              byweekday=(TU,TH),
230
 
                              dtstart=parse("19970902T090000"))),
231
 
                         [datetime(1998, 1, 1, 9, 0),
232
 
                          datetime(1998, 1, 6, 9, 0),
233
 
                          datetime(1998, 1, 8, 9, 0)])
234
 
 
235
 
    def testYearlyByMonthAndNWeekDay(self):
236
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
237
 
                              count=3,
238
 
                              bymonth=(1,3),
239
 
                              byweekday=(TU(1),TH(-1)),
240
 
                              dtstart=parse("19970902T090000"))),
241
 
                         [datetime(1998, 1, 6, 9, 0),
242
 
                          datetime(1998, 1, 29, 9, 0),
243
 
                          datetime(1998, 3, 3, 9, 0)])
244
 
 
245
 
    def testYearlyByMonthAndNWeekDayLarge(self):
246
 
        # This is interesting because the TH(-3) ends up before
247
 
        # the TU(3).
248
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
249
 
                              count=3,
250
 
                              bymonth=(1,3),
251
 
                              byweekday=(TU(3),TH(-3)),
252
 
                              dtstart=parse("19970902T090000"))),
253
 
                         [datetime(1998, 1, 15, 9, 0),
254
 
                          datetime(1998, 1, 20, 9, 0),
255
 
                          datetime(1998, 3, 12, 9, 0)])
256
 
 
257
 
    def testYearlyByMonthDayAndWeekDay(self):
258
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
259
 
                              count=3,
260
 
                              bymonthday=(1,3),
261
 
                              byweekday=(TU,TH),
262
 
                              dtstart=parse("19970902T090000"))),
263
 
                         [datetime(1998, 1, 1, 9, 0),
264
 
                          datetime(1998, 2, 3, 9, 0),
265
 
                          datetime(1998, 3, 3, 9, 0)])
266
 
 
267
 
    def testYearlyByMonthAndMonthDayAndWeekDay(self):
268
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
269
 
                              count=3,
270
 
                              bymonth=(1,3),
271
 
                              bymonthday=(1,3),
272
 
                              byweekday=(TU,TH),
273
 
                              dtstart=parse("19970902T090000"))),
274
 
                         [datetime(1998, 1, 1, 9, 0),
275
 
                          datetime(1998, 3, 3, 9, 0),
276
 
                          datetime(2001, 3, 1, 9, 0)])
277
 
 
278
 
    def testYearlyByYearDay(self):
279
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
280
 
                              count=3,
281
 
                              byyearday=(1,100,200),
282
 
                              dtstart=parse("19970902T090000"))),
283
 
                         [datetime(1998, 1, 1, 9, 0),
284
 
                          datetime(1998, 4, 10, 9, 0),
285
 
                          datetime(1998, 7, 19, 9, 0)])
286
 
 
287
 
    def testYearlyByMonthAndYearDay(self):
288
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
289
 
                              count=3,
290
 
                              bymonth=(4,7),
291
 
                              byyearday=(1,100,200),
292
 
                              dtstart=parse("19970902T090000"))),
293
 
                         [datetime(1998, 4, 10, 9, 0),
294
 
                          datetime(1998, 7, 19, 9, 0),
295
 
                          datetime(1999, 4, 10, 9, 0)])
296
 
 
297
 
    def testYearlyByWeekNo(self):
298
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
299
 
                              count=3,
300
 
                              byweekno=20,
301
 
                              dtstart=parse("19970902T090000"))),
302
 
                         [datetime(1998, 5, 11, 9, 0),
303
 
                          datetime(1998, 5, 12, 9, 0),
304
 
                          datetime(1998, 5, 13, 9, 0)])
305
 
 
306
 
    def testYearlyByWeekNoAndWeekDay(self):
307
 
        # That's a nice one. The first days of week number one
308
 
        # may be in the last year.
309
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
310
 
                              count=3,
311
 
                              byweekno=1,
312
 
                              byweekday=MO,
313
 
                              dtstart=parse("19970902T090000"))),
314
 
                         [datetime(1997, 12, 29, 9, 0),
315
 
                          datetime(1999, 1, 4, 9, 0),
316
 
                          datetime(2000, 1, 3, 9, 0)])
317
 
 
318
 
    def testYearlyByWeekNoAndWeekDayLarge(self):
319
 
        # Another nice test. The last days of week number 52/53
320
 
        # may be in the next year.
321
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
322
 
                              count=3,
323
 
                              byweekno=52,
324
 
                              byweekday=SU,
325
 
                              dtstart=parse("19970902T090000"))),
326
 
                         [datetime(1997, 12, 28, 9, 0),
327
 
                          datetime(1998, 12, 27, 9, 0),
328
 
                          datetime(2000, 1, 2, 9, 0)])
329
 
 
330
 
    def testYearlyByWeekNoAndWeekDayLast(self):
331
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
332
 
                              count=3,
333
 
                              byweekno=-1,
334
 
                              byweekday=SU,
335
 
                              dtstart=parse("19970902T090000"))),
336
 
                         [datetime(1997, 12, 28, 9, 0),
337
 
                          datetime(1999, 1, 3, 9, 0),
338
 
                          datetime(2000, 1, 2, 9, 0)])
339
 
 
340
 
    def testYearlyByEaster(self):
341
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
342
 
                              count=3,
343
 
                              byeaster=0,
344
 
                              dtstart=parse("19970902T090000"))),
345
 
                         [datetime(1998, 4, 12, 9, 0),
346
 
                          datetime(1999, 4, 4, 9, 0),
347
 
                          datetime(2000, 4, 23, 9, 0)])
348
 
 
349
 
    def testYearlyByEasterPos(self):
350
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
351
 
                              count=3,
352
 
                              byeaster=1,
353
 
                              dtstart=parse("19970902T090000"))),
354
 
                         [datetime(1998, 4, 13, 9, 0),
355
 
                          datetime(1999, 4, 5, 9, 0),
356
 
                          datetime(2000, 4, 24, 9, 0)])
357
 
 
358
 
    def testYearlyByEasterNeg(self):
359
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
360
 
                              count=3,
361
 
                              byeaster=-1,
362
 
                              dtstart=parse("19970902T090000"))),
363
 
                         [datetime(1998, 4, 11, 9, 0),
364
 
                          datetime(1999, 4, 3, 9, 0),
365
 
                          datetime(2000, 4, 22, 9, 0)])
366
 
 
367
 
    def testYearlyByWeekNoAndWeekDay53(self):
368
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
369
 
                              count=3,
370
 
                              byweekno=53,
371
 
                              byweekday=MO,
372
 
                              dtstart=parse("19970902T090000"))),
373
 
                         [datetime(1998, 12, 28, 9, 0),
374
 
                          datetime(2004, 12, 27, 9, 0),
375
 
                          datetime(2009, 12, 28, 9, 0)])
376
 
 
377
 
    def testYearlyByWeekNoAndWeekDay53(self):
378
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
379
 
                              count=3,
380
 
                              byweekno=53,
381
 
                              byweekday=MO,
382
 
                              dtstart=parse("19970902T090000"))),
383
 
                         [datetime(1998, 12, 28, 9, 0),
384
 
                          datetime(2004, 12, 27, 9, 0),
385
 
                          datetime(2009, 12, 28, 9, 0)])
386
 
 
387
 
    def testYearlyByHour(self):
388
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
389
 
                              count=3,
390
 
                              byhour=(6,18),
391
 
                              dtstart=parse("19970902T090000"))),
392
 
                         [datetime(1997, 9, 2, 18, 0),
393
 
                          datetime(1998, 9, 2, 6, 0),
394
 
                          datetime(1998, 9, 2, 18, 0)])
395
 
 
396
 
    def testYearlyByMinute(self):
397
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
398
 
                              count=3,
399
 
                              byminute=(6,18),
400
 
                              dtstart=parse("19970902T090000"))),
401
 
                         [datetime(1997, 9, 2, 9, 6),
402
 
                          datetime(1997, 9, 2, 9, 18),
403
 
                          datetime(1998, 9, 2, 9, 6)])
404
 
 
405
 
    def testYearlyBySecond(self):
406
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
407
 
                              count=3,
408
 
                              bysecond=(6,18),
409
 
                              dtstart=parse("19970902T090000"))),
410
 
                         [datetime(1997, 9, 2, 9, 0, 6),
411
 
                          datetime(1997, 9, 2, 9, 0, 18),
412
 
                          datetime(1998, 9, 2, 9, 0, 6)])
413
 
 
414
 
    def testYearlyByHourAndMinute(self):
415
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
416
 
                              count=3,
417
 
                              byhour=(6,18),
418
 
                              byminute=(6,18),
419
 
                              dtstart=parse("19970902T090000"))),
420
 
                         [datetime(1997, 9, 2, 18, 6),
421
 
                          datetime(1997, 9, 2, 18, 18),
422
 
                          datetime(1998, 9, 2, 6, 6)])
423
 
 
424
 
    def testYearlyByHourAndSecond(self):
425
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
426
 
                              count=3,
427
 
                              byhour=(6,18),
428
 
                              bysecond=(6,18),
429
 
                              dtstart=parse("19970902T090000"))),
430
 
                         [datetime(1997, 9, 2, 18, 0, 6),
431
 
                          datetime(1997, 9, 2, 18, 0, 18),
432
 
                          datetime(1998, 9, 2, 6, 0, 6)])
433
 
 
434
 
    def testYearlyByMinuteAndSecond(self):
435
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
436
 
                              count=3,
437
 
                              byminute=(6,18),
438
 
                              bysecond=(6,18),
439
 
                              dtstart=parse("19970902T090000"))),
440
 
                         [datetime(1997, 9, 2, 9, 6, 6),
441
 
                          datetime(1997, 9, 2, 9, 6, 18),
442
 
                          datetime(1997, 9, 2, 9, 18, 6)])
443
 
 
444
 
    def testYearlyByHourAndMinuteAndSecond(self):
445
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
446
 
                              count=3,
447
 
                              byhour=(6,18),
448
 
                              byminute=(6,18),
449
 
                              bysecond=(6,18),
450
 
                              dtstart=parse("19970902T090000"))),
451
 
                         [datetime(1997, 9, 2, 18, 6, 6),
452
 
                          datetime(1997, 9, 2, 18, 6, 18),
453
 
                          datetime(1997, 9, 2, 18, 18, 6)])
454
 
 
455
 
    def testYearlyBySetPos(self):
456
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
457
 
                              count=3,
458
 
                              bymonthday=15,
459
 
                              byhour=(6,18),
460
 
                              bysetpos=(3,-3),
461
 
                              dtstart=parse("19970902T090000"))),
462
 
                         [datetime(1997, 11, 15, 18, 0),
463
 
                          datetime(1998, 2, 15, 6, 0),
464
 
                          datetime(1998, 11, 15, 18, 0)])
465
 
 
466
 
    def testMonthly(self):
467
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
468
 
                              count=3,
469
 
                              dtstart=parse("19970902T090000"))),
470
 
                         [datetime(1997, 9, 2, 9, 0),
471
 
                          datetime(1997, 10, 2, 9, 0),
472
 
                          datetime(1997, 11, 2, 9, 0)])
473
 
 
474
 
    def testMonthlyInterval(self):
475
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
476
 
                              count=3,
477
 
                              interval=2,
478
 
                              dtstart=parse("19970902T090000"))),
479
 
                         [datetime(1997, 9, 2, 9, 0),
480
 
                          datetime(1997, 11, 2, 9, 0),
481
 
                          datetime(1998, 1, 2, 9, 0)])
482
 
 
483
 
    def testMonthlyIntervalLarge(self):
484
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
485
 
                              count=3,
486
 
                              interval=18,
487
 
                              dtstart=parse("19970902T090000"))),
488
 
                         [datetime(1997, 9, 2, 9, 0),
489
 
                          datetime(1999, 3, 2, 9, 0),
490
 
                          datetime(2000, 9, 2, 9, 0)])
491
 
 
492
 
    def testMonthlyByMonth(self):
493
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
494
 
                              count=3,
495
 
                              bymonth=(1,3),
496
 
                              dtstart=parse("19970902T090000"))),
497
 
                         [datetime(1998, 1, 2, 9, 0),
498
 
                          datetime(1998, 3, 2, 9, 0),
499
 
                          datetime(1999, 1, 2, 9, 0)])
500
 
 
501
 
 
502
 
    def testMonthlyByMonthDay(self):
503
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
504
 
                              count=3,
505
 
                              bymonthday=(1,3),
506
 
                              dtstart=parse("19970902T090000"))),
507
 
                         [datetime(1997, 9, 3, 9, 0),
508
 
                          datetime(1997, 10, 1, 9, 0),
509
 
                          datetime(1997, 10, 3, 9, 0)])
510
 
 
511
 
    def testMonthlyByMonthAndMonthDay(self):
512
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
513
 
                              count=3,
514
 
                              bymonth=(1,3),
515
 
                              bymonthday=(5,7),
516
 
                              dtstart=parse("19970902T090000"))),
517
 
                         [datetime(1998, 1, 5, 9, 0),
518
 
                          datetime(1998, 1, 7, 9, 0),
519
 
                          datetime(1998, 3, 5, 9, 0)])
520
 
 
521
 
    def testMonthlyByWeekDay(self):
522
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
523
 
                              count=3,
524
 
                              byweekday=(TU,TH),
525
 
                              dtstart=parse("19970902T090000"))),
526
 
                         [datetime(1997, 9, 2, 9, 0),
527
 
                          datetime(1997, 9, 4, 9, 0),
528
 
                          datetime(1997, 9, 9, 9, 0)])
529
 
 
530
 
    def testMonthlyByNWeekDay(self):
531
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
532
 
                              count=3,
533
 
                              byweekday=(TU(1),TH(-1)),
534
 
                              dtstart=parse("19970902T090000"))),
535
 
                         [datetime(1997, 9, 2, 9, 0),
536
 
                          datetime(1997, 9, 25, 9, 0),
537
 
                          datetime(1997, 10, 7, 9, 0)])
538
 
 
539
 
    def testMonthlyByNWeekDayLarge(self):
540
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
541
 
                              count=3,
542
 
                              byweekday=(TU(3),TH(-3)),
543
 
                              dtstart=parse("19970902T090000"))),
544
 
                         [datetime(1997, 9, 11, 9, 0),
545
 
                          datetime(1997, 9, 16, 9, 0),
546
 
                          datetime(1997, 10, 16, 9, 0)])
547
 
 
548
 
    def testMonthlyByMonthAndWeekDay(self):
549
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
550
 
                              count=3,
551
 
                              bymonth=(1,3),
552
 
                              byweekday=(TU,TH),
553
 
                              dtstart=parse("19970902T090000"))),
554
 
                         [datetime(1998, 1, 1, 9, 0),
555
 
                          datetime(1998, 1, 6, 9, 0),
556
 
                          datetime(1998, 1, 8, 9, 0)])
557
 
 
558
 
    def testMonthlyByMonthAndNWeekDay(self):
559
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
560
 
                              count=3,
561
 
                              bymonth=(1,3),
562
 
                              byweekday=(TU(1),TH(-1)),
563
 
                              dtstart=parse("19970902T090000"))),
564
 
                         [datetime(1998, 1, 6, 9, 0),
565
 
                          datetime(1998, 1, 29, 9, 0),
566
 
                          datetime(1998, 3, 3, 9, 0)])
567
 
 
568
 
    def testMonthlyByMonthAndNWeekDayLarge(self):
569
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
570
 
                              count=3,
571
 
                              bymonth=(1,3),
572
 
                              byweekday=(TU(3),TH(-3)),
573
 
                              dtstart=parse("19970902T090000"))),
574
 
                         [datetime(1998, 1, 15, 9, 0),
575
 
                          datetime(1998, 1, 20, 9, 0),
576
 
                          datetime(1998, 3, 12, 9, 0)])
577
 
 
578
 
    def testMonthlyByMonthDayAndWeekDay(self):
579
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
580
 
                              count=3,
581
 
                              bymonthday=(1,3),
582
 
                              byweekday=(TU,TH),
583
 
                              dtstart=parse("19970902T090000"))),
584
 
                         [datetime(1998, 1, 1, 9, 0),
585
 
                          datetime(1998, 2, 3, 9, 0),
586
 
                          datetime(1998, 3, 3, 9, 0)])
587
 
 
588
 
    def testMonthlyByMonthAndMonthDayAndWeekDay(self):
589
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
590
 
                              count=3,
591
 
                              bymonth=(1,3),
592
 
                              bymonthday=(1,3),
593
 
                              byweekday=(TU,TH),
594
 
                              dtstart=parse("19970902T090000"))),
595
 
                         [datetime(1998, 1, 1, 9, 0),
596
 
                          datetime(1998, 3, 3, 9, 0),
597
 
                          datetime(2001, 3, 1, 9, 0)])
598
 
 
599
 
    def testMonthlyByYearDay(self):
600
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
601
 
                              count=3,
602
 
                              byyearday=(1,100,200),
603
 
                              dtstart=parse("19970902T090000"))),
604
 
                         [datetime(1998, 1, 1, 9, 0),
605
 
                          datetime(1998, 4, 10, 9, 0),
606
 
                          datetime(1998, 7, 19, 9, 0)])
607
 
 
608
 
    def testMonthlyByMonthAndYearDay(self):
609
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
610
 
                              count=3,
611
 
                              bymonth=(4,7),
612
 
                              byyearday=(1,100,200),
613
 
                              dtstart=parse("19970902T090000"))),
614
 
                         [datetime(1998, 4, 10, 9, 0),
615
 
                          datetime(1998, 7, 19, 9, 0),
616
 
                          datetime(1999, 4, 10, 9, 0)])
617
 
 
618
 
    def testMonthlyByWeekNo(self):
619
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
620
 
                              count=3,
621
 
                              byweekno=20,
622
 
                              dtstart=parse("19970902T090000"))),
623
 
                         [datetime(1998, 5, 11, 9, 0),
624
 
                          datetime(1998, 5, 12, 9, 0),
625
 
                          datetime(1998, 5, 13, 9, 0)])
626
 
 
627
 
    def testMonthlyByWeekNoAndWeekDay(self):
628
 
        # That's a nice one. The first days of week number one
629
 
        # may be in the last year.
630
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
631
 
                              count=3,
632
 
                              byweekno=1,
633
 
                              byweekday=MO,
634
 
                              dtstart=parse("19970902T090000"))),
635
 
                         [datetime(1997, 12, 29, 9, 0),
636
 
                          datetime(1999, 1, 4, 9, 0),
637
 
                          datetime(2000, 1, 3, 9, 0)])
638
 
 
639
 
    def testMonthlyByWeekNoAndWeekDayLarge(self):
640
 
        # Another nice test. The last days of week number 52/53
641
 
        # may be in the next year.
642
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
643
 
                              count=3,
644
 
                              byweekno=52,
645
 
                              byweekday=SU,
646
 
                              dtstart=parse("19970902T090000"))),
647
 
                         [datetime(1997, 12, 28, 9, 0),
648
 
                          datetime(1998, 12, 27, 9, 0),
649
 
                          datetime(2000, 1, 2, 9, 0)])
650
 
 
651
 
    def testMonthlyByWeekNoAndWeekDayLast(self):
652
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
653
 
                              count=3,
654
 
                              byweekno=-1,
655
 
                              byweekday=SU,
656
 
                              dtstart=parse("19970902T090000"))),
657
 
                         [datetime(1997, 12, 28, 9, 0),
658
 
                          datetime(1999, 1, 3, 9, 0),
659
 
                          datetime(2000, 1, 2, 9, 0)])
660
 
 
661
 
    def testMonthlyByWeekNoAndWeekDay53(self):
662
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
663
 
                              count=3,
664
 
                              byweekno=53,
665
 
                              byweekday=MO,
666
 
                              dtstart=parse("19970902T090000"))),
667
 
                         [datetime(1998, 12, 28, 9, 0),
668
 
                          datetime(2004, 12, 27, 9, 0),
669
 
                          datetime(2009, 12, 28, 9, 0)])
670
 
 
671
 
    def testMonthlyByEaster(self):
672
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
673
 
                              count=3,
674
 
                              byeaster=0,
675
 
                              dtstart=parse("19970902T090000"))),
676
 
                         [datetime(1998, 4, 12, 9, 0),
677
 
                          datetime(1999, 4, 4, 9, 0),
678
 
                          datetime(2000, 4, 23, 9, 0)])
679
 
 
680
 
    def testMonthlyByEasterPos(self):
681
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
682
 
                              count=3,
683
 
                              byeaster=1,
684
 
                              dtstart=parse("19970902T090000"))),
685
 
                         [datetime(1998, 4, 13, 9, 0),
686
 
                          datetime(1999, 4, 5, 9, 0),
687
 
                          datetime(2000, 4, 24, 9, 0)])
688
 
 
689
 
    def testMonthlyByEasterNeg(self):
690
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
691
 
                              count=3,
692
 
                              byeaster=-1,
693
 
                              dtstart=parse("19970902T090000"))),
694
 
                         [datetime(1998, 4, 11, 9, 0),
695
 
                          datetime(1999, 4, 3, 9, 0),
696
 
                          datetime(2000, 4, 22, 9, 0)])
697
 
 
698
 
    def testMonthlyByHour(self):
699
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
700
 
                              count=3,
701
 
                              byhour=(6,18),
702
 
                              dtstart=parse("19970902T090000"))),
703
 
                         [datetime(1997, 9, 2, 18, 0),
704
 
                          datetime(1997, 10, 2, 6, 0),
705
 
                          datetime(1997, 10, 2, 18, 0)])
706
 
 
707
 
    def testMonthlyByMinute(self):
708
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
709
 
                              count=3,
710
 
                              byminute=(6,18),
711
 
                              dtstart=parse("19970902T090000"))),
712
 
                         [datetime(1997, 9, 2, 9, 6),
713
 
                          datetime(1997, 9, 2, 9, 18),
714
 
                          datetime(1997, 10, 2, 9, 6)])
715
 
 
716
 
    def testMonthlyBySecond(self):
717
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
718
 
                              count=3,
719
 
                              bysecond=(6,18),
720
 
                              dtstart=parse("19970902T090000"))),
721
 
                         [datetime(1997, 9, 2, 9, 0, 6),
722
 
                          datetime(1997, 9, 2, 9, 0, 18),
723
 
                          datetime(1997, 10, 2, 9, 0, 6)])
724
 
 
725
 
    def testMonthlyByHourAndMinute(self):
726
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
727
 
                              count=3,
728
 
                              byhour=(6,18),
729
 
                              byminute=(6,18),
730
 
                              dtstart=parse("19970902T090000"))),
731
 
                         [datetime(1997, 9, 2, 18, 6),
732
 
                          datetime(1997, 9, 2, 18, 18),
733
 
                          datetime(1997, 10, 2, 6, 6)])
734
 
 
735
 
    def testMonthlyByHourAndSecond(self):
736
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
737
 
                              count=3,
738
 
                              byhour=(6,18),
739
 
                              bysecond=(6,18),
740
 
                              dtstart=parse("19970902T090000"))),
741
 
                         [datetime(1997, 9, 2, 18, 0, 6),
742
 
                          datetime(1997, 9, 2, 18, 0, 18),
743
 
                          datetime(1997, 10, 2, 6, 0, 6)])
744
 
 
745
 
    def testMonthlyByMinuteAndSecond(self):
746
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
747
 
                              count=3,
748
 
                              byminute=(6,18),
749
 
                              bysecond=(6,18),
750
 
                              dtstart=parse("19970902T090000"))),
751
 
                         [datetime(1997, 9, 2, 9, 6, 6),
752
 
                          datetime(1997, 9, 2, 9, 6, 18),
753
 
                          datetime(1997, 9, 2, 9, 18, 6)])
754
 
 
755
 
    def testMonthlyByHourAndMinuteAndSecond(self):
756
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
757
 
                              count=3,
758
 
                              byhour=(6,18),
759
 
                              byminute=(6,18),
760
 
                              bysecond=(6,18),
761
 
                              dtstart=parse("19970902T090000"))),
762
 
                         [datetime(1997, 9, 2, 18, 6, 6),
763
 
                          datetime(1997, 9, 2, 18, 6, 18),
764
 
                          datetime(1997, 9, 2, 18, 18, 6)])
765
 
 
766
 
    def testMonthlyBySetPos(self):
767
 
        self.assertEqual(list(rrule(FREQ_MONTHLY,
768
 
                              count=3,
769
 
                              bymonthday=(13,17),
770
 
                              byhour=(6,18),
771
 
                              bysetpos=(3,-3),
772
 
                              dtstart=parse("19970902T090000"))),
773
 
                         [datetime(1997, 9, 13, 18, 0),
774
 
                          datetime(1997, 9, 17, 6, 0),
775
 
                          datetime(1997, 10, 13, 18, 0)])
776
 
 
777
 
    def testWeekly(self):
778
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
779
 
                              count=3,
780
 
                              dtstart=parse("19970902T090000"))),
781
 
                         [datetime(1997, 9, 2, 9, 0),
782
 
                          datetime(1997, 9, 9, 9, 0),
783
 
                          datetime(1997, 9, 16, 9, 0)])
784
 
 
785
 
    def testWeeklyInterval(self):
786
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
787
 
                              count=3,
788
 
                              interval=2,
789
 
                              dtstart=parse("19970902T090000"))),
790
 
                         [datetime(1997, 9, 2, 9, 0),
791
 
                          datetime(1997, 9, 16, 9, 0),
792
 
                          datetime(1997, 9, 30, 9, 0)])
793
 
 
794
 
    def testWeeklyIntervalLarge(self):
795
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
796
 
                              count=3,
797
 
                              interval=20,
798
 
                              dtstart=parse("19970902T090000"))),
799
 
                         [datetime(1997, 9, 2, 9, 0),
800
 
                          datetime(1998, 1, 20, 9, 0),
801
 
                          datetime(1998, 6, 9, 9, 0)])
802
 
 
803
 
    def testWeeklyByMonth(self):
804
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
805
 
                              count=3,
806
 
                              bymonth=(1,3),
807
 
                              dtstart=parse("19970902T090000"))),
808
 
                         [datetime(1998, 1, 6, 9, 0),
809
 
                          datetime(1998, 1, 13, 9, 0),
810
 
                          datetime(1998, 1, 20, 9, 0)])
811
 
 
812
 
    def testWeeklyByMonthDay(self):
813
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
814
 
                              count=3,
815
 
                              bymonthday=(1,3),
816
 
                              dtstart=parse("19970902T090000"))),
817
 
                         [datetime(1997, 9, 3, 9, 0),
818
 
                          datetime(1997, 10, 1, 9, 0),
819
 
                          datetime(1997, 10, 3, 9, 0)])
820
 
 
821
 
    def testWeeklyByMonthAndMonthDay(self):
822
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
823
 
                              count=3,
824
 
                              bymonth=(1,3),
825
 
                              bymonthday=(5,7),
826
 
                              dtstart=parse("19970902T090000"))),
827
 
                         [datetime(1998, 1, 5, 9, 0),
828
 
                          datetime(1998, 1, 7, 9, 0),
829
 
                          datetime(1998, 3, 5, 9, 0)])
830
 
 
831
 
    def testWeeklyByWeekDay(self):
832
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
833
 
                              count=3,
834
 
                              byweekday=(TU,TH),
835
 
                              dtstart=parse("19970902T090000"))),
836
 
                         [datetime(1997, 9, 2, 9, 0),
837
 
                          datetime(1997, 9, 4, 9, 0),
838
 
                          datetime(1997, 9, 9, 9, 0)])
839
 
 
840
 
    def testWeeklyByNWeekDay(self):
841
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
842
 
                              count=3,
843
 
                              byweekday=(TU(1),TH(-1)),
844
 
                              dtstart=parse("19970902T090000"))),
845
 
                         [datetime(1997, 9, 2, 9, 0),
846
 
                          datetime(1997, 9, 4, 9, 0),
847
 
                          datetime(1997, 9, 9, 9, 0)])
848
 
 
849
 
    def testWeeklyByMonthAndWeekDay(self):
850
 
        # This test is interesting, because it crosses the year
851
 
        # boundary in a weekly period to find day '1' as a
852
 
        # valid recurrence.
853
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
854
 
                              count=3,
855
 
                              bymonth=(1,3),
856
 
                              byweekday=(TU,TH),
857
 
                              dtstart=parse("19970902T090000"))),
858
 
                         [datetime(1998, 1, 1, 9, 0),
859
 
                          datetime(1998, 1, 6, 9, 0),
860
 
                          datetime(1998, 1, 8, 9, 0)])
861
 
 
862
 
    def testWeeklyByMonthAndNWeekDay(self):
863
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
864
 
                              count=3,
865
 
                              bymonth=(1,3),
866
 
                              byweekday=(TU(1),TH(-1)),
867
 
                              dtstart=parse("19970902T090000"))),
868
 
                         [datetime(1998, 1, 1, 9, 0),
869
 
                          datetime(1998, 1, 6, 9, 0),
870
 
                          datetime(1998, 1, 8, 9, 0)])
871
 
 
872
 
    def testWeeklyByMonthDayAndWeekDay(self):
873
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
874
 
                              count=3,
875
 
                              bymonthday=(1,3),
876
 
                              byweekday=(TU,TH),
877
 
                              dtstart=parse("19970902T090000"))),
878
 
                         [datetime(1998, 1, 1, 9, 0),
879
 
                          datetime(1998, 2, 3, 9, 0),
880
 
                          datetime(1998, 3, 3, 9, 0)])
881
 
 
882
 
    def testWeeklyByMonthAndMonthDayAndWeekDay(self):
883
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
884
 
                              count=3,
885
 
                              bymonth=(1,3),
886
 
                              bymonthday=(1,3),
887
 
                              byweekday=(TU,TH),
888
 
                              dtstart=parse("19970902T090000"))),
889
 
                         [datetime(1998, 1, 1, 9, 0),
890
 
                          datetime(1998, 3, 3, 9, 0),
891
 
                          datetime(2001, 3, 1, 9, 0)])
892
 
 
893
 
    def testWeeklyByYearDay(self):
894
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
895
 
                              count=3,
896
 
                              byyearday=(1,100,200),
897
 
                              dtstart=parse("19970902T090000"))),
898
 
                         [datetime(1998, 1, 1, 9, 0),
899
 
                          datetime(1998, 4, 10, 9, 0),
900
 
                          datetime(1998, 7, 19, 9, 0)])
901
 
 
902
 
    def testWeeklyByMonthAndYearDay(self):
903
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
904
 
                              count=3,
905
 
                              bymonth=(1,7),
906
 
                              byyearday=(1,100,200),
907
 
                              dtstart=parse("19970902T090000"))),
908
 
                         [datetime(1998, 1, 1, 9, 0),
909
 
                          datetime(1998, 7, 19, 9, 0),
910
 
                          datetime(1999, 1, 1, 9, 0)])
911
 
 
912
 
    def testWeeklyByWeekNo(self):
913
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
914
 
                              count=3,
915
 
                              byweekno=20,
916
 
                              dtstart=parse("19970902T090000"))),
917
 
                         [datetime(1998, 5, 11, 9, 0),
918
 
                          datetime(1998, 5, 12, 9, 0),
919
 
                          datetime(1998, 5, 13, 9, 0)])
920
 
 
921
 
    def testWeeklyByWeekNoAndWeekDay(self):
922
 
        # That's a nice one. The first days of week number one
923
 
        # may be in the last year.
924
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
925
 
                              count=3,
926
 
                              byweekno=1,
927
 
                              byweekday=MO,
928
 
                              dtstart=parse("19970902T090000"))),
929
 
                         [datetime(1997, 12, 29, 9, 0),
930
 
                          datetime(1999, 1, 4, 9, 0),
931
 
                          datetime(2000, 1, 3, 9, 0)])
932
 
 
933
 
    def testWeeklyByWeekNoAndWeekDayLarge(self):
934
 
        # Another nice test. The last days of week number 52/53
935
 
        # may be in the next year.
936
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
937
 
                              count=3,
938
 
                              byweekno=52,
939
 
                              byweekday=SU,
940
 
                              dtstart=parse("19970902T090000"))),
941
 
                         [datetime(1997, 12, 28, 9, 0),
942
 
                          datetime(1998, 12, 27, 9, 0),
943
 
                          datetime(2000, 1, 2, 9, 0)])
944
 
 
945
 
    def testWeeklyByWeekNoAndWeekDayLast(self):
946
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
947
 
                              count=3,
948
 
                              byweekno=-1,
949
 
                              byweekday=SU,
950
 
                              dtstart=parse("19970902T090000"))),
951
 
                         [datetime(1997, 12, 28, 9, 0),
952
 
                          datetime(1999, 1, 3, 9, 0),
953
 
                          datetime(2000, 1, 2, 9, 0)])
954
 
 
955
 
    def testWeeklyByWeekNoAndWeekDay53(self):
956
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
957
 
                              count=3,
958
 
                              byweekno=53,
959
 
                              byweekday=MO,
960
 
                              dtstart=parse("19970902T090000"))),
961
 
                         [datetime(1998, 12, 28, 9, 0),
962
 
                          datetime(2004, 12, 27, 9, 0),
963
 
                          datetime(2009, 12, 28, 9, 0)])
964
 
 
965
 
    def testWeeklyByEaster(self):
966
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
967
 
                              count=3,
968
 
                              byeaster=0,
969
 
                              dtstart=parse("19970902T090000"))),
970
 
                         [datetime(1998, 4, 12, 9, 0),
971
 
                          datetime(1999, 4, 4, 9, 0),
972
 
                          datetime(2000, 4, 23, 9, 0)])
973
 
 
974
 
    def testWeeklyByEasterPos(self):
975
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
976
 
                              count=3,
977
 
                              byeaster=1,
978
 
                              dtstart=parse("19970902T090000"))),
979
 
                         [datetime(1998, 4, 13, 9, 0),
980
 
                          datetime(1999, 4, 5, 9, 0),
981
 
                          datetime(2000, 4, 24, 9, 0)])
982
 
 
983
 
    def testWeeklyByEasterNeg(self):
984
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
985
 
                              count=3,
986
 
                              byeaster=-1,
987
 
                              dtstart=parse("19970902T090000"))),
988
 
                         [datetime(1998, 4, 11, 9, 0),
989
 
                          datetime(1999, 4, 3, 9, 0),
990
 
                          datetime(2000, 4, 22, 9, 0)])
991
 
 
992
 
    def testWeeklyByHour(self):
993
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
994
 
                              count=3,
995
 
                              byhour=(6,18),
996
 
                              dtstart=parse("19970902T090000"))),
997
 
                         [datetime(1997, 9, 2, 18, 0),
998
 
                          datetime(1997, 9, 9, 6, 0),
999
 
                          datetime(1997, 9, 9, 18, 0)])
1000
 
 
1001
 
    def testWeeklyByMinute(self):
1002
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
1003
 
                              count=3,
1004
 
                              byminute=(6,18),
1005
 
                              dtstart=parse("19970902T090000"))),
1006
 
                         [datetime(1997, 9, 2, 9, 6),
1007
 
                          datetime(1997, 9, 2, 9, 18),
1008
 
                          datetime(1997, 9, 9, 9, 6)])
1009
 
 
1010
 
    def testWeeklyBySecond(self):
1011
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
1012
 
                              count=3,
1013
 
                              bysecond=(6,18),
1014
 
                              dtstart=parse("19970902T090000"))),
1015
 
                         [datetime(1997, 9, 2, 9, 0, 6),
1016
 
                          datetime(1997, 9, 2, 9, 0, 18),
1017
 
                          datetime(1997, 9, 9, 9, 0, 6)])
1018
 
 
1019
 
    def testWeeklyByHourAndMinute(self):
1020
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
1021
 
                              count=3,
1022
 
                              byhour=(6,18),
1023
 
                              byminute=(6,18),
1024
 
                              dtstart=parse("19970902T090000"))),
1025
 
                         [datetime(1997, 9, 2, 18, 6),
1026
 
                          datetime(1997, 9, 2, 18, 18),
1027
 
                          datetime(1997, 9, 9, 6, 6)])
1028
 
 
1029
 
    def testWeeklyByHourAndSecond(self):
1030
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
1031
 
                              count=3,
1032
 
                              byhour=(6,18),
1033
 
                              bysecond=(6,18),
1034
 
                              dtstart=parse("19970902T090000"))),
1035
 
                         [datetime(1997, 9, 2, 18, 0, 6),
1036
 
                          datetime(1997, 9, 2, 18, 0, 18),
1037
 
                          datetime(1997, 9, 9, 6, 0, 6)])
1038
 
 
1039
 
    def testWeeklyByMinuteAndSecond(self):
1040
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
1041
 
                              count=3,
1042
 
                              byminute=(6,18),
1043
 
                              bysecond=(6,18),
1044
 
                              dtstart=parse("19970902T090000"))),
1045
 
                         [datetime(1997, 9, 2, 9, 6, 6),
1046
 
                          datetime(1997, 9, 2, 9, 6, 18),
1047
 
                          datetime(1997, 9, 2, 9, 18, 6)])
1048
 
 
1049
 
    def testWeeklyByHourAndMinuteAndSecond(self):
1050
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
1051
 
                              count=3,
1052
 
                              byhour=(6,18),
1053
 
                              byminute=(6,18),
1054
 
                              bysecond=(6,18),
1055
 
                              dtstart=parse("19970902T090000"))),
1056
 
                         [datetime(1997, 9, 2, 18, 6, 6),
1057
 
                          datetime(1997, 9, 2, 18, 6, 18),
1058
 
                          datetime(1997, 9, 2, 18, 18, 6)])
1059
 
 
1060
 
    def testWeeklyBySetPos(self):
1061
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
1062
 
                              count=3,
1063
 
                              byweekday=(TU,TH),
1064
 
                              byhour=(6,18),
1065
 
                              bysetpos=(3,-3),
1066
 
                              dtstart=parse("19970902T090000"))),
1067
 
                         [datetime(1997, 9, 2, 18, 0),
1068
 
                          datetime(1997, 9, 4, 6, 0),
1069
 
                          datetime(1997, 9, 9, 18, 0)])
1070
 
 
1071
 
    def testDaily(self):
1072
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1073
 
                              count=3,
1074
 
                              dtstart=parse("19970902T090000"))),
1075
 
                         [datetime(1997, 9, 2, 9, 0),
1076
 
                          datetime(1997, 9, 3, 9, 0),
1077
 
                          datetime(1997, 9, 4, 9, 0)])
1078
 
 
1079
 
    def testDailyInterval(self):
1080
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1081
 
                              count=3,
1082
 
                              interval=2,
1083
 
                              dtstart=parse("19970902T090000"))),
1084
 
                         [datetime(1997, 9, 2, 9, 0),
1085
 
                          datetime(1997, 9, 4, 9, 0),
1086
 
                          datetime(1997, 9, 6, 9, 0)])
1087
 
 
1088
 
    def testDailyIntervalLarge(self):
1089
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1090
 
                              count=3,
1091
 
                              interval=92,
1092
 
                              dtstart=parse("19970902T090000"))),
1093
 
                         [datetime(1997, 9, 2, 9, 0),
1094
 
                          datetime(1997, 12, 3, 9, 0),
1095
 
                          datetime(1998, 3, 5, 9, 0)])
1096
 
 
1097
 
    def testDailyByMonth(self):
1098
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1099
 
                              count=3,
1100
 
                              bymonth=(1,3),
1101
 
                              dtstart=parse("19970902T090000"))),
1102
 
                         [datetime(1998, 1, 1, 9, 0),
1103
 
                          datetime(1998, 1, 2, 9, 0),
1104
 
                          datetime(1998, 1, 3, 9, 0)])
1105
 
 
1106
 
    def testDailyByMonthDay(self):
1107
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1108
 
                              count=3,
1109
 
                              bymonthday=(1,3),
1110
 
                              dtstart=parse("19970902T090000"))),
1111
 
                         [datetime(1997, 9, 3, 9, 0),
1112
 
                          datetime(1997, 10, 1, 9, 0),
1113
 
                          datetime(1997, 10, 3, 9, 0)])
1114
 
 
1115
 
    def testDailyByMonthAndMonthDay(self):
1116
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1117
 
                              count=3,
1118
 
                              bymonth=(1,3),
1119
 
                              bymonthday=(5,7),
1120
 
                              dtstart=parse("19970902T090000"))),
1121
 
                         [datetime(1998, 1, 5, 9, 0),
1122
 
                          datetime(1998, 1, 7, 9, 0),
1123
 
                          datetime(1998, 3, 5, 9, 0)])
1124
 
 
1125
 
    def testDailyByWeekDay(self):
1126
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1127
 
                              count=3,
1128
 
                              byweekday=(TU,TH),
1129
 
                              dtstart=parse("19970902T090000"))),
1130
 
                         [datetime(1997, 9, 2, 9, 0),
1131
 
                          datetime(1997, 9, 4, 9, 0),
1132
 
                          datetime(1997, 9, 9, 9, 0)])
1133
 
 
1134
 
    def testDailyByNWeekDay(self):
1135
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1136
 
                              count=3,
1137
 
                              byweekday=(TU(1),TH(-1)),
1138
 
                              dtstart=parse("19970902T090000"))),
1139
 
                         [datetime(1997, 9, 2, 9, 0),
1140
 
                          datetime(1997, 9, 4, 9, 0),
1141
 
                          datetime(1997, 9, 9, 9, 0)])
1142
 
 
1143
 
    def testDailyByMonthAndWeekDay(self):
1144
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1145
 
                              count=3,
1146
 
                              bymonth=(1,3),
1147
 
                              byweekday=(TU,TH),
1148
 
                              dtstart=parse("19970902T090000"))),
1149
 
                         [datetime(1998, 1, 1, 9, 0),
1150
 
                          datetime(1998, 1, 6, 9, 0),
1151
 
                          datetime(1998, 1, 8, 9, 0)])
1152
 
 
1153
 
    def testDailyByMonthAndNWeekDay(self):
1154
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1155
 
                              count=3,
1156
 
                              bymonth=(1,3),
1157
 
                              byweekday=(TU(1),TH(-1)),
1158
 
                              dtstart=parse("19970902T090000"))),
1159
 
                         [datetime(1998, 1, 1, 9, 0),
1160
 
                          datetime(1998, 1, 6, 9, 0),
1161
 
                          datetime(1998, 1, 8, 9, 0)])
1162
 
 
1163
 
    def testDailyByMonthDayAndWeekDay(self):
1164
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1165
 
                              count=3,
1166
 
                              bymonthday=(1,3),
1167
 
                              byweekday=(TU,TH),
1168
 
                              dtstart=parse("19970902T090000"))),
1169
 
                         [datetime(1998, 1, 1, 9, 0),
1170
 
                          datetime(1998, 2, 3, 9, 0),
1171
 
                          datetime(1998, 3, 3, 9, 0)])
1172
 
 
1173
 
    def testDailyByMonthAndMonthDayAndWeekDay(self):
1174
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1175
 
                              count=3,
1176
 
                              bymonth=(1,3),
1177
 
                              bymonthday=(1,3),
1178
 
                              byweekday=(TU,TH),
1179
 
                              dtstart=parse("19970902T090000"))),
1180
 
                         [datetime(1998, 1, 1, 9, 0),
1181
 
                          datetime(1998, 3, 3, 9, 0),
1182
 
                          datetime(2001, 3, 1, 9, 0)])
1183
 
 
1184
 
    def testDailyByYearDay(self):
1185
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1186
 
                              count=3,
1187
 
                              byyearday=(1,100,200),
1188
 
                              dtstart=parse("19970902T090000"))),
1189
 
                         [datetime(1998, 1, 1, 9, 0),
1190
 
                          datetime(1998, 4, 10, 9, 0),
1191
 
                          datetime(1998, 7, 19, 9, 0)])
1192
 
 
1193
 
    def testDailyByMonthAndYearDay(self):
1194
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1195
 
                              count=3,
1196
 
                              bymonth=(1,7),
1197
 
                              byyearday=(1,100,200),
1198
 
                              dtstart=parse("19970902T090000"))),
1199
 
                         [datetime(1998, 1, 1, 9, 0),
1200
 
                          datetime(1998, 7, 19, 9, 0),
1201
 
                          datetime(1999, 1, 1, 9, 0)])
1202
 
 
1203
 
    def testDailyByWeekNo(self):
1204
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1205
 
                              count=3,
1206
 
                              byweekno=20,
1207
 
                              dtstart=parse("19970902T090000"))),
1208
 
                         [datetime(1998, 5, 11, 9, 0),
1209
 
                          datetime(1998, 5, 12, 9, 0),
1210
 
                          datetime(1998, 5, 13, 9, 0)])
1211
 
 
1212
 
    def testDailyByWeekNoAndWeekDay(self):
1213
 
        # That's a nice one. The first days of week number one
1214
 
        # may be in the last year.
1215
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1216
 
                              count=3,
1217
 
                              byweekno=1,
1218
 
                              byweekday=MO,
1219
 
                              dtstart=parse("19970902T090000"))),
1220
 
                         [datetime(1997, 12, 29, 9, 0),
1221
 
                          datetime(1999, 1, 4, 9, 0),
1222
 
                          datetime(2000, 1, 3, 9, 0)])
1223
 
 
1224
 
    def testDailyByWeekNoAndWeekDayLarge(self):
1225
 
        # Another nice test. The last days of week number 52/53
1226
 
        # may be in the next year.
1227
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1228
 
                              count=3,
1229
 
                              byweekno=52,
1230
 
                              byweekday=SU,
1231
 
                              dtstart=parse("19970902T090000"))),
1232
 
                         [datetime(1997, 12, 28, 9, 0),
1233
 
                          datetime(1998, 12, 27, 9, 0),
1234
 
                          datetime(2000, 1, 2, 9, 0)])
1235
 
 
1236
 
    def testDailyByWeekNoAndWeekDayLast(self):
1237
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1238
 
                              count=3,
1239
 
                              byweekno=-1,
1240
 
                              byweekday=SU,
1241
 
                              dtstart=parse("19970902T090000"))),
1242
 
                         [datetime(1997, 12, 28, 9, 0),
1243
 
                          datetime(1999, 1, 3, 9, 0),
1244
 
                          datetime(2000, 1, 2, 9, 0)])
1245
 
 
1246
 
    def testDailyByWeekNoAndWeekDay53(self):
1247
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1248
 
                              count=3,
1249
 
                              byweekno=53,
1250
 
                              byweekday=MO,
1251
 
                              dtstart=parse("19970902T090000"))),
1252
 
                         [datetime(1998, 12, 28, 9, 0),
1253
 
                          datetime(2004, 12, 27, 9, 0),
1254
 
                          datetime(2009, 12, 28, 9, 0)])
1255
 
 
1256
 
    def testDailyByEaster(self):
1257
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1258
 
                              count=3,
1259
 
                              byeaster=0,
1260
 
                              dtstart=parse("19970902T090000"))),
1261
 
                         [datetime(1998, 4, 12, 9, 0),
1262
 
                          datetime(1999, 4, 4, 9, 0),
1263
 
                          datetime(2000, 4, 23, 9, 0)])
1264
 
 
1265
 
    def testDailyByEasterPos(self):
1266
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1267
 
                              count=3,
1268
 
                              byeaster=1,
1269
 
                              dtstart=parse("19970902T090000"))),
1270
 
                         [datetime(1998, 4, 13, 9, 0),
1271
 
                          datetime(1999, 4, 5, 9, 0),
1272
 
                          datetime(2000, 4, 24, 9, 0)])
1273
 
 
1274
 
    def testDailyByEasterNeg(self):
1275
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1276
 
                              count=3,
1277
 
                              byeaster=-1,
1278
 
                              dtstart=parse("19970902T090000"))),
1279
 
                         [datetime(1998, 4, 11, 9, 0),
1280
 
                          datetime(1999, 4, 3, 9, 0),
1281
 
                          datetime(2000, 4, 22, 9, 0)])
1282
 
 
1283
 
    def testDailyByHour(self):
1284
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1285
 
                              count=3,
1286
 
                              byhour=(6,18),
1287
 
                              dtstart=parse("19970902T090000"))),
1288
 
                         [datetime(1997, 9, 2, 18, 0),
1289
 
                          datetime(1997, 9, 3, 6, 0),
1290
 
                          datetime(1997, 9, 3, 18, 0)])
1291
 
 
1292
 
    def testDailyByMinute(self):
1293
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1294
 
                              count=3,
1295
 
                              byminute=(6,18),
1296
 
                              dtstart=parse("19970902T090000"))),
1297
 
                         [datetime(1997, 9, 2, 9, 6),
1298
 
                          datetime(1997, 9, 2, 9, 18),
1299
 
                          datetime(1997, 9, 3, 9, 6)])
1300
 
 
1301
 
    def testDailyBySecond(self):
1302
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1303
 
                              count=3,
1304
 
                              bysecond=(6,18),
1305
 
                              dtstart=parse("19970902T090000"))),
1306
 
                         [datetime(1997, 9, 2, 9, 0, 6),
1307
 
                          datetime(1997, 9, 2, 9, 0, 18),
1308
 
                          datetime(1997, 9, 3, 9, 0, 6)])
1309
 
 
1310
 
    def testDailyByHourAndMinute(self):
1311
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1312
 
                              count=3,
1313
 
                              byhour=(6,18),
1314
 
                              byminute=(6,18),
1315
 
                              dtstart=parse("19970902T090000"))),
1316
 
                         [datetime(1997, 9, 2, 18, 6),
1317
 
                          datetime(1997, 9, 2, 18, 18),
1318
 
                          datetime(1997, 9, 3, 6, 6)])
1319
 
 
1320
 
    def testDailyByHourAndSecond(self):
1321
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1322
 
                              count=3,
1323
 
                              byhour=(6,18),
1324
 
                              bysecond=(6,18),
1325
 
                              dtstart=parse("19970902T090000"))),
1326
 
                         [datetime(1997, 9, 2, 18, 0, 6),
1327
 
                          datetime(1997, 9, 2, 18, 0, 18),
1328
 
                          datetime(1997, 9, 3, 6, 0, 6)])
1329
 
 
1330
 
    def testDailyByMinuteAndSecond(self):
1331
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1332
 
                              count=3,
1333
 
                              byminute=(6,18),
1334
 
                              bysecond=(6,18),
1335
 
                              dtstart=parse("19970902T090000"))),
1336
 
                         [datetime(1997, 9, 2, 9, 6, 6),
1337
 
                          datetime(1997, 9, 2, 9, 6, 18),
1338
 
                          datetime(1997, 9, 2, 9, 18, 6)])
1339
 
 
1340
 
    def testDailyByHourAndMinuteAndSecond(self):
1341
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1342
 
                              count=3,
1343
 
                              byhour=(6,18),
1344
 
                              byminute=(6,18),
1345
 
                              bysecond=(6,18),
1346
 
                              dtstart=parse("19970902T090000"))),
1347
 
                         [datetime(1997, 9, 2, 18, 6, 6),
1348
 
                          datetime(1997, 9, 2, 18, 6, 18),
1349
 
                          datetime(1997, 9, 2, 18, 18, 6)])
1350
 
 
1351
 
    def testDailyBySetPos(self):
1352
 
        self.assertEqual(list(rrule(FREQ_DAILY,
1353
 
                              count=3,
1354
 
                              byhour=(6,18),
1355
 
                              byminute=(15,45),
1356
 
                              bysetpos=(3,-3),
1357
 
                              dtstart=parse("19970902T090000"))),
1358
 
                         [datetime(1997, 9, 2, 18, 15),
1359
 
                          datetime(1997, 9, 3, 6, 45),
1360
 
                          datetime(1997, 9, 3, 18, 15)])
1361
 
 
1362
 
    def testHourly(self):
1363
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1364
 
                              count=3,
1365
 
                              dtstart=parse("19970902T090000"))),
1366
 
                         [datetime(1997, 9, 2, 9, 0),
1367
 
                          datetime(1997, 9, 2, 10, 0),
1368
 
                          datetime(1997, 9, 2, 11, 0)])
1369
 
 
1370
 
    def testHourlyInterval(self):
1371
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1372
 
                              count=3,
1373
 
                              interval=2,
1374
 
                              dtstart=parse("19970902T090000"))),
1375
 
                         [datetime(1997, 9, 2, 9, 0),
1376
 
                          datetime(1997, 9, 2, 11, 0),
1377
 
                          datetime(1997, 9, 2, 13, 0)])
1378
 
 
1379
 
    def testHourlyIntervalLarge(self):
1380
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1381
 
                              count=3,
1382
 
                              interval=769,
1383
 
                              dtstart=parse("19970902T090000"))),
1384
 
                         [datetime(1997, 9, 2, 9, 0),
1385
 
                          datetime(1997, 10, 4, 10, 0),
1386
 
                          datetime(1997, 11, 5, 11, 0)])
1387
 
 
1388
 
    def testHourlyByMonth(self):
1389
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1390
 
                              count=3,
1391
 
                              bymonth=(1,3),
1392
 
                              dtstart=parse("19970902T090000"))),
1393
 
                         [datetime(1998, 1, 1, 0, 0),
1394
 
                          datetime(1998, 1, 1, 1, 0),
1395
 
                          datetime(1998, 1, 1, 2, 0)])
1396
 
 
1397
 
    def testHourlyByMonthDay(self):
1398
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1399
 
                              count=3,
1400
 
                              bymonthday=(1,3),
1401
 
                              dtstart=parse("19970902T090000"))),
1402
 
                         [datetime(1997, 9, 3, 0, 0),
1403
 
                          datetime(1997, 9, 3, 1, 0),
1404
 
                          datetime(1997, 9, 3, 2, 0)])
1405
 
 
1406
 
    def testHourlyByMonthAndMonthDay(self):
1407
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1408
 
                              count=3,
1409
 
                              bymonth=(1,3),
1410
 
                              bymonthday=(5,7),
1411
 
                              dtstart=parse("19970902T090000"))),
1412
 
                         [datetime(1998, 1, 5, 0, 0),
1413
 
                          datetime(1998, 1, 5, 1, 0),
1414
 
                          datetime(1998, 1, 5, 2, 0)])
1415
 
 
1416
 
    def testHourlyByWeekDay(self):
1417
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1418
 
                              count=3,
1419
 
                              byweekday=(TU,TH),
1420
 
                              dtstart=parse("19970902T090000"))),
1421
 
                         [datetime(1997, 9, 2, 9, 0),
1422
 
                          datetime(1997, 9, 2, 10, 0),
1423
 
                          datetime(1997, 9, 2, 11, 0)])
1424
 
 
1425
 
    def testHourlyByNWeekDay(self):
1426
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1427
 
                              count=3,
1428
 
                              byweekday=(TU(1),TH(-1)),
1429
 
                              dtstart=parse("19970902T090000"))),
1430
 
                         [datetime(1997, 9, 2, 9, 0),
1431
 
                          datetime(1997, 9, 2, 10, 0),
1432
 
                          datetime(1997, 9, 2, 11, 0)])
1433
 
 
1434
 
    def testHourlyByMonthAndWeekDay(self):
1435
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1436
 
                              count=3,
1437
 
                              bymonth=(1,3),
1438
 
                              byweekday=(TU,TH),
1439
 
                              dtstart=parse("19970902T090000"))),
1440
 
                         [datetime(1998, 1, 1, 0, 0),
1441
 
                          datetime(1998, 1, 1, 1, 0),
1442
 
                          datetime(1998, 1, 1, 2, 0)])
1443
 
 
1444
 
    def testHourlyByMonthAndNWeekDay(self):
1445
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1446
 
                              count=3,
1447
 
                              bymonth=(1,3),
1448
 
                              byweekday=(TU(1),TH(-1)),
1449
 
                              dtstart=parse("19970902T090000"))),
1450
 
                         [datetime(1998, 1, 1, 0, 0),
1451
 
                          datetime(1998, 1, 1, 1, 0),
1452
 
                          datetime(1998, 1, 1, 2, 0)])
1453
 
 
1454
 
    def testHourlyByMonthDayAndWeekDay(self):
1455
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1456
 
                              count=3,
1457
 
                              bymonthday=(1,3),
1458
 
                              byweekday=(TU,TH),
1459
 
                              dtstart=parse("19970902T090000"))),
1460
 
                         [datetime(1998, 1, 1, 0, 0),
1461
 
                          datetime(1998, 1, 1, 1, 0),
1462
 
                          datetime(1998, 1, 1, 2, 0)])
1463
 
 
1464
 
    def testHourlyByMonthAndMonthDayAndWeekDay(self):
1465
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1466
 
                              count=3,
1467
 
                              bymonth=(1,3),
1468
 
                              bymonthday=(1,3),
1469
 
                              byweekday=(TU,TH),
1470
 
                              dtstart=parse("19970902T090000"))),
1471
 
                         [datetime(1998, 1, 1, 0, 0),
1472
 
                          datetime(1998, 1, 1, 1, 0),
1473
 
                          datetime(1998, 1, 1, 2, 0)])
1474
 
 
1475
 
    def testHourlyByYearDay(self):
1476
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1477
 
                              count=3,
1478
 
                              byyearday=(1,100,200),
1479
 
                              dtstart=parse("19970902T090000"))),
1480
 
                         [datetime(1998, 1, 1, 0, 0),
1481
 
                          datetime(1998, 1, 1, 1, 0),
1482
 
                          datetime(1998, 1, 1, 2, 0)])
1483
 
 
1484
 
    def testHourlyByMonthAndYearDay(self):
1485
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1486
 
                              count=3,
1487
 
                              bymonth=(4,7),
1488
 
                              byyearday=(1,100,200),
1489
 
                              dtstart=parse("19970902T090000"))),
1490
 
                         [datetime(1998, 4, 10, 0, 0),
1491
 
                          datetime(1998, 4, 10, 1, 0),
1492
 
                          datetime(1998, 4, 10, 2, 0)])
1493
 
 
1494
 
    def testHourlyByWeekNo(self):
1495
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1496
 
                              count=3,
1497
 
                              byweekno=20,
1498
 
                              dtstart=parse("19970902T090000"))),
1499
 
                         [datetime(1998, 5, 11, 0, 0),
1500
 
                          datetime(1998, 5, 11, 1, 0),
1501
 
                          datetime(1998, 5, 11, 2, 0)])
1502
 
 
1503
 
    def testHourlyByWeekNoAndWeekDay(self):
1504
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1505
 
                              count=3,
1506
 
                              byweekno=1,
1507
 
                              byweekday=MO,
1508
 
                              dtstart=parse("19970902T090000"))),
1509
 
                         [datetime(1997, 12, 29, 0, 0),
1510
 
                          datetime(1997, 12, 29, 1, 0),
1511
 
                          datetime(1997, 12, 29, 2, 0)])
1512
 
 
1513
 
    def testHourlyByWeekNoAndWeekDayLarge(self):
1514
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1515
 
                              count=3,
1516
 
                              byweekno=52,
1517
 
                              byweekday=SU,
1518
 
                              dtstart=parse("19970902T090000"))),
1519
 
                         [datetime(1997, 12, 28, 0, 0),
1520
 
                          datetime(1997, 12, 28, 1, 0),
1521
 
                          datetime(1997, 12, 28, 2, 0)])
1522
 
 
1523
 
    def testHourlyByWeekNoAndWeekDayLast(self):
1524
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1525
 
                              count=3,
1526
 
                              byweekno=-1,
1527
 
                              byweekday=SU,
1528
 
                              dtstart=parse("19970902T090000"))),
1529
 
                         [datetime(1997, 12, 28, 0, 0),
1530
 
                          datetime(1997, 12, 28, 1, 0),
1531
 
                          datetime(1997, 12, 28, 2, 0)])
1532
 
 
1533
 
    def testHourlyByWeekNoAndWeekDay53(self):
1534
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1535
 
                              count=3,
1536
 
                              byweekno=53,
1537
 
                              byweekday=MO,
1538
 
                              dtstart=parse("19970902T090000"))),
1539
 
                         [datetime(1998, 12, 28, 0, 0),
1540
 
                          datetime(1998, 12, 28, 1, 0),
1541
 
                          datetime(1998, 12, 28, 2, 0)])
1542
 
 
1543
 
    def testHourlyByEaster(self):
1544
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1545
 
                              count=3,
1546
 
                              byeaster=0,
1547
 
                              dtstart=parse("19970902T090000"))),
1548
 
                         [datetime(1998, 4, 12, 0, 0),
1549
 
                          datetime(1998, 4, 12, 1, 0),
1550
 
                          datetime(1998, 4, 12, 2, 0)])
1551
 
 
1552
 
    def testHourlyByEasterPos(self):
1553
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1554
 
                              count=3,
1555
 
                              byeaster=1,
1556
 
                              dtstart=parse("19970902T090000"))),
1557
 
                         [datetime(1998, 4, 13, 0, 0),
1558
 
                          datetime(1998, 4, 13, 1, 0),
1559
 
                          datetime(1998, 4, 13, 2, 0)])
1560
 
 
1561
 
    def testHourlyByEasterNeg(self):
1562
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1563
 
                              count=3,
1564
 
                              byeaster=-1,
1565
 
                              dtstart=parse("19970902T090000"))),
1566
 
                         [datetime(1998, 4, 11, 0, 0),
1567
 
                          datetime(1998, 4, 11, 1, 0),
1568
 
                          datetime(1998, 4, 11, 2, 0)])
1569
 
 
1570
 
    def testHourlyByHour(self):
1571
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1572
 
                              count=3,
1573
 
                              byhour=(6,18),
1574
 
                              dtstart=parse("19970902T090000"))),
1575
 
                         [datetime(1997, 9, 2, 18, 0),
1576
 
                          datetime(1997, 9, 3, 6, 0),
1577
 
                          datetime(1997, 9, 3, 18, 0)])
1578
 
 
1579
 
    def testHourlyByMinute(self):
1580
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1581
 
                              count=3,
1582
 
                              byminute=(6,18),
1583
 
                              dtstart=parse("19970902T090000"))),
1584
 
                         [datetime(1997, 9, 2, 9, 6),
1585
 
                          datetime(1997, 9, 2, 9, 18),
1586
 
                          datetime(1997, 9, 2, 10, 6)])
1587
 
 
1588
 
    def testHourlyBySecond(self):
1589
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1590
 
                              count=3,
1591
 
                              bysecond=(6,18),
1592
 
                              dtstart=parse("19970902T090000"))),
1593
 
                         [datetime(1997, 9, 2, 9, 0, 6),
1594
 
                          datetime(1997, 9, 2, 9, 0, 18),
1595
 
                          datetime(1997, 9, 2, 10, 0, 6)])
1596
 
 
1597
 
    def testHourlyByHourAndMinute(self):
1598
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1599
 
                              count=3,
1600
 
                              byhour=(6,18),
1601
 
                              byminute=(6,18),
1602
 
                              dtstart=parse("19970902T090000"))),
1603
 
                         [datetime(1997, 9, 2, 18, 6),
1604
 
                          datetime(1997, 9, 2, 18, 18),
1605
 
                          datetime(1997, 9, 3, 6, 6)])
1606
 
 
1607
 
    def testHourlyByHourAndSecond(self):
1608
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1609
 
                              count=3,
1610
 
                              byhour=(6,18),
1611
 
                              bysecond=(6,18),
1612
 
                              dtstart=parse("19970902T090000"))),
1613
 
                         [datetime(1997, 9, 2, 18, 0, 6),
1614
 
                          datetime(1997, 9, 2, 18, 0, 18),
1615
 
                          datetime(1997, 9, 3, 6, 0, 6)])
1616
 
 
1617
 
    def testHourlyByMinuteAndSecond(self):
1618
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1619
 
                              count=3,
1620
 
                              byminute=(6,18),
1621
 
                              bysecond=(6,18),
1622
 
                              dtstart=parse("19970902T090000"))),
1623
 
                         [datetime(1997, 9, 2, 9, 6, 6),
1624
 
                          datetime(1997, 9, 2, 9, 6, 18),
1625
 
                          datetime(1997, 9, 2, 9, 18, 6)])
1626
 
 
1627
 
    def testHourlyByHourAndMinuteAndSecond(self):
1628
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1629
 
                              count=3,
1630
 
                              byhour=(6,18),
1631
 
                              byminute=(6,18),
1632
 
                              bysecond=(6,18),
1633
 
                              dtstart=parse("19970902T090000"))),
1634
 
                         [datetime(1997, 9, 2, 18, 6, 6),
1635
 
                          datetime(1997, 9, 2, 18, 6, 18),
1636
 
                          datetime(1997, 9, 2, 18, 18, 6)])
1637
 
 
1638
 
    def testHourlyBySetPos(self):
1639
 
        self.assertEqual(list(rrule(FREQ_HOURLY,
1640
 
                              count=3,
1641
 
                              byminute=(15,45),
1642
 
                              bysecond=(15,45),
1643
 
                              bysetpos=(3,-3),
1644
 
                              dtstart=parse("19970902T090000"))),
1645
 
                         [datetime(1997, 9, 2, 9, 15, 45),
1646
 
                          datetime(1997, 9, 2, 9, 45, 15),
1647
 
                          datetime(1997, 9, 2, 10, 15, 45)])
1648
 
 
1649
 
    def testMinutely(self):
1650
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1651
 
                              count=3,
1652
 
                              dtstart=parse("19970902T090000"))),
1653
 
                         [datetime(1997, 9, 2, 9, 0),
1654
 
                          datetime(1997, 9, 2, 9, 1),
1655
 
                          datetime(1997, 9, 2, 9, 2)])
1656
 
 
1657
 
    def testMinutelyInterval(self):
1658
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1659
 
                              count=3,
1660
 
                              interval=2,
1661
 
                              dtstart=parse("19970902T090000"))),
1662
 
                         [datetime(1997, 9, 2, 9, 0),
1663
 
                          datetime(1997, 9, 2, 9, 2),
1664
 
                          datetime(1997, 9, 2, 9, 4)])
1665
 
 
1666
 
    def testMinutelyIntervalLarge(self):
1667
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1668
 
                              count=3,
1669
 
                              interval=1501,
1670
 
                              dtstart=parse("19970902T090000"))),
1671
 
                         [datetime(1997, 9, 2, 9, 0),
1672
 
                          datetime(1997, 9, 3, 10, 1),
1673
 
                          datetime(1997, 9, 4, 11, 2)])
1674
 
 
1675
 
    def testMinutelyByMonth(self):
1676
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1677
 
                              count=3,
1678
 
                              bymonth=(1,3),
1679
 
                              dtstart=parse("19970902T090000"))),
1680
 
                         [datetime(1998, 1, 1, 0, 0),
1681
 
                          datetime(1998, 1, 1, 0, 1),
1682
 
                          datetime(1998, 1, 1, 0, 2)])
1683
 
 
1684
 
    def testMinutelyByMonthDay(self):
1685
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1686
 
                              count=3,
1687
 
                              bymonthday=(1,3),
1688
 
                              dtstart=parse("19970902T090000"))),
1689
 
                         [datetime(1997, 9, 3, 0, 0),
1690
 
                          datetime(1997, 9, 3, 0, 1),
1691
 
                          datetime(1997, 9, 3, 0, 2)])
1692
 
 
1693
 
    def testMinutelyByMonthAndMonthDay(self):
1694
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1695
 
                              count=3,
1696
 
                              bymonth=(1,3),
1697
 
                              bymonthday=(5,7),
1698
 
                              dtstart=parse("19970902T090000"))),
1699
 
                         [datetime(1998, 1, 5, 0, 0),
1700
 
                          datetime(1998, 1, 5, 0, 1),
1701
 
                          datetime(1998, 1, 5, 0, 2)])
1702
 
 
1703
 
    def testMinutelyByWeekDay(self):
1704
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1705
 
                              count=3,
1706
 
                              byweekday=(TU,TH),
1707
 
                              dtstart=parse("19970902T090000"))),
1708
 
                         [datetime(1997, 9, 2, 9, 0),
1709
 
                          datetime(1997, 9, 2, 9, 1),
1710
 
                          datetime(1997, 9, 2, 9, 2)])
1711
 
 
1712
 
    def testMinutelyByNWeekDay(self):
1713
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1714
 
                              count=3,
1715
 
                              byweekday=(TU(1),TH(-1)),
1716
 
                              dtstart=parse("19970902T090000"))),
1717
 
                         [datetime(1997, 9, 2, 9, 0),
1718
 
                          datetime(1997, 9, 2, 9, 1),
1719
 
                          datetime(1997, 9, 2, 9, 2)])
1720
 
 
1721
 
    def testMinutelyByMonthAndWeekDay(self):
1722
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1723
 
                              count=3,
1724
 
                              bymonth=(1,3),
1725
 
                              byweekday=(TU,TH),
1726
 
                              dtstart=parse("19970902T090000"))),
1727
 
                         [datetime(1998, 1, 1, 0, 0),
1728
 
                          datetime(1998, 1, 1, 0, 1),
1729
 
                          datetime(1998, 1, 1, 0, 2)])
1730
 
 
1731
 
    def testMinutelyByMonthAndNWeekDay(self):
1732
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1733
 
                              count=3,
1734
 
                              bymonth=(1,3),
1735
 
                              byweekday=(TU(1),TH(-1)),
1736
 
                              dtstart=parse("19970902T090000"))),
1737
 
                         [datetime(1998, 1, 1, 0, 0),
1738
 
                          datetime(1998, 1, 1, 0, 1),
1739
 
                          datetime(1998, 1, 1, 0, 2)])
1740
 
 
1741
 
    def testMinutelyByMonthDayAndWeekDay(self):
1742
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1743
 
                              count=3,
1744
 
                              bymonthday=(1,3),
1745
 
                              byweekday=(TU,TH),
1746
 
                              dtstart=parse("19970902T090000"))),
1747
 
                         [datetime(1998, 1, 1, 0, 0),
1748
 
                          datetime(1998, 1, 1, 0, 1),
1749
 
                          datetime(1998, 1, 1, 0, 2)])
1750
 
 
1751
 
    def testMinutelyByMonthAndMonthDayAndWeekDay(self):
1752
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1753
 
                              count=3,
1754
 
                              bymonth=(1,3),
1755
 
                              bymonthday=(1,3),
1756
 
                              byweekday=(TU,TH),
1757
 
                              dtstart=parse("19970902T090000"))),
1758
 
                         [datetime(1998, 1, 1, 0, 0),
1759
 
                          datetime(1998, 1, 1, 0, 1),
1760
 
                          datetime(1998, 1, 1, 0, 2)])
1761
 
 
1762
 
    def testMinutelyByYearDay(self):
1763
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1764
 
                              count=3,
1765
 
                              byyearday=(1,100,200),
1766
 
                              dtstart=parse("19970902T090000"))),
1767
 
                         [datetime(1998, 1, 1, 0, 0),
1768
 
                          datetime(1998, 1, 1, 0, 1),
1769
 
                          datetime(1998, 1, 1, 0, 2)])
1770
 
 
1771
 
    def testMinutelyByMonthAndYearDay(self):
1772
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1773
 
                              count=3,
1774
 
                              bymonth=(4,7),
1775
 
                              byyearday=(1,100,200),
1776
 
                              dtstart=parse("19970902T090000"))),
1777
 
                         [datetime(1998, 4, 10, 0, 0),
1778
 
                          datetime(1998, 4, 10, 0, 1),
1779
 
                          datetime(1998, 4, 10, 0, 2)])
1780
 
 
1781
 
    def testMinutelyByWeekNo(self):
1782
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1783
 
                              count=3,
1784
 
                              byweekno=20,
1785
 
                              dtstart=parse("19970902T090000"))),
1786
 
                         [datetime(1998, 5, 11, 0, 0),
1787
 
                          datetime(1998, 5, 11, 0, 1),
1788
 
                          datetime(1998, 5, 11, 0, 2)])
1789
 
 
1790
 
    def testMinutelyByWeekNoAndWeekDay(self):
1791
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1792
 
                              count=3,
1793
 
                              byweekno=1,
1794
 
                              byweekday=MO,
1795
 
                              dtstart=parse("19970902T090000"))),
1796
 
                         [datetime(1997, 12, 29, 0, 0),
1797
 
                          datetime(1997, 12, 29, 0, 1),
1798
 
                          datetime(1997, 12, 29, 0, 2)])
1799
 
 
1800
 
    def testMinutelyByWeekNoAndWeekDayLarge(self):
1801
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1802
 
                              count=3,
1803
 
                              byweekno=52,
1804
 
                              byweekday=SU,
1805
 
                              dtstart=parse("19970902T090000"))),
1806
 
                         [datetime(1997, 12, 28, 0, 0),
1807
 
                          datetime(1997, 12, 28, 0, 1),
1808
 
                          datetime(1997, 12, 28, 0, 2)])
1809
 
 
1810
 
    def testMinutelyByWeekNoAndWeekDayLast(self):
1811
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1812
 
                              count=3,
1813
 
                              byweekno=-1,
1814
 
                              byweekday=SU,
1815
 
                              dtstart=parse("19970902T090000"))),
1816
 
                         [datetime(1997, 12, 28, 0, 0),
1817
 
                          datetime(1997, 12, 28, 0, 1),
1818
 
                          datetime(1997, 12, 28, 0, 2)])
1819
 
 
1820
 
    def testMinutelyByWeekNoAndWeekDay53(self):
1821
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1822
 
                              count=3,
1823
 
                              byweekno=53,
1824
 
                              byweekday=MO,
1825
 
                              dtstart=parse("19970902T090000"))),
1826
 
                         [datetime(1998, 12, 28, 0, 0),
1827
 
                          datetime(1998, 12, 28, 0, 1),
1828
 
                          datetime(1998, 12, 28, 0, 2)])
1829
 
 
1830
 
    def testMinutelyByEaster(self):
1831
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1832
 
                              count=3,
1833
 
                              byeaster=0,
1834
 
                              dtstart=parse("19970902T090000"))),
1835
 
                         [datetime(1998, 4, 12, 0, 0),
1836
 
                          datetime(1998, 4, 12, 0, 1),
1837
 
                          datetime(1998, 4, 12, 0, 2)])
1838
 
 
1839
 
    def testMinutelyByEasterPos(self):
1840
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1841
 
                              count=3,
1842
 
                              byeaster=1,
1843
 
                              dtstart=parse("19970902T090000"))),
1844
 
                         [datetime(1998, 4, 13, 0, 0),
1845
 
                          datetime(1998, 4, 13, 0, 1),
1846
 
                          datetime(1998, 4, 13, 0, 2)])
1847
 
 
1848
 
    def testMinutelyByEasterNeg(self):
1849
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1850
 
                              count=3,
1851
 
                              byeaster=-1,
1852
 
                              dtstart=parse("19970902T090000"))),
1853
 
                         [datetime(1998, 4, 11, 0, 0),
1854
 
                          datetime(1998, 4, 11, 0, 1),
1855
 
                          datetime(1998, 4, 11, 0, 2)])
1856
 
 
1857
 
    def testMinutelyByHour(self):
1858
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1859
 
                              count=3,
1860
 
                              byhour=(6,18),
1861
 
                              dtstart=parse("19970902T090000"))),
1862
 
                         [datetime(1997, 9, 2, 18, 0),
1863
 
                          datetime(1997, 9, 2, 18, 1),
1864
 
                          datetime(1997, 9, 2, 18, 2)])
1865
 
 
1866
 
    def testMinutelyByMinute(self):
1867
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1868
 
                              count=3,
1869
 
                              byminute=(6,18),
1870
 
                              dtstart=parse("19970902T090000"))),
1871
 
                         [datetime(1997, 9, 2, 9, 6),
1872
 
                          datetime(1997, 9, 2, 9, 18),
1873
 
                          datetime(1997, 9, 2, 10, 6)])
1874
 
 
1875
 
    def testMinutelyBySecond(self):
1876
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1877
 
                              count=3,
1878
 
                              bysecond=(6,18),
1879
 
                              dtstart=parse("19970902T090000"))),
1880
 
                         [datetime(1997, 9, 2, 9, 0, 6),
1881
 
                          datetime(1997, 9, 2, 9, 0, 18),
1882
 
                          datetime(1997, 9, 2, 9, 1, 6)])
1883
 
 
1884
 
    def testMinutelyByHourAndMinute(self):
1885
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1886
 
                              count=3,
1887
 
                              byhour=(6,18),
1888
 
                              byminute=(6,18),
1889
 
                              dtstart=parse("19970902T090000"))),
1890
 
                         [datetime(1997, 9, 2, 18, 6),
1891
 
                          datetime(1997, 9, 2, 18, 18),
1892
 
                          datetime(1997, 9, 3, 6, 6)])
1893
 
 
1894
 
    def testMinutelyByHourAndSecond(self):
1895
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1896
 
                              count=3,
1897
 
                              byhour=(6,18),
1898
 
                              bysecond=(6,18),
1899
 
                              dtstart=parse("19970902T090000"))),
1900
 
                         [datetime(1997, 9, 2, 18, 0, 6),
1901
 
                          datetime(1997, 9, 2, 18, 0, 18),
1902
 
                          datetime(1997, 9, 2, 18, 1, 6)])
1903
 
 
1904
 
    def testMinutelyByMinuteAndSecond(self):
1905
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1906
 
                              count=3,
1907
 
                              byminute=(6,18),
1908
 
                              bysecond=(6,18),
1909
 
                              dtstart=parse("19970902T090000"))),
1910
 
                         [datetime(1997, 9, 2, 9, 6, 6),
1911
 
                          datetime(1997, 9, 2, 9, 6, 18),
1912
 
                          datetime(1997, 9, 2, 9, 18, 6)])
1913
 
 
1914
 
    def testMinutelyByHourAndMinuteAndSecond(self):
1915
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1916
 
                              count=3,
1917
 
                              byhour=(6,18),
1918
 
                              byminute=(6,18),
1919
 
                              bysecond=(6,18),
1920
 
                              dtstart=parse("19970902T090000"))),
1921
 
                         [datetime(1997, 9, 2, 18, 6, 6),
1922
 
                          datetime(1997, 9, 2, 18, 6, 18),
1923
 
                          datetime(1997, 9, 2, 18, 18, 6)])
1924
 
 
1925
 
    def testMinutelyBySetPos(self):
1926
 
        self.assertEqual(list(rrule(FREQ_MINUTELY,
1927
 
                              count=3,
1928
 
                              bysecond=(15,30,45),
1929
 
                              bysetpos=(3,-3),
1930
 
                              dtstart=parse("19970902T090000"))),
1931
 
                         [datetime(1997, 9, 2, 9, 0, 15),
1932
 
                          datetime(1997, 9, 2, 9, 0, 45),
1933
 
                          datetime(1997, 9, 2, 9, 1, 15)])
1934
 
 
1935
 
    def testSecondly(self):
1936
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
1937
 
                              count=3,
1938
 
                              dtstart=parse("19970902T090000"))),
1939
 
                         [datetime(1997, 9, 2, 9, 0, 0),
1940
 
                          datetime(1997, 9, 2, 9, 0, 1),
1941
 
                          datetime(1997, 9, 2, 9, 0, 2)])
1942
 
 
1943
 
    def testSecondlyInterval(self):
1944
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
1945
 
                              count=3,
1946
 
                              interval=2,
1947
 
                              dtstart=parse("19970902T090000"))),
1948
 
                         [datetime(1997, 9, 2, 9, 0, 0),
1949
 
                          datetime(1997, 9, 2, 9, 0, 2),
1950
 
                          datetime(1997, 9, 2, 9, 0, 4)])
1951
 
 
1952
 
    def testSecondlyIntervalLarge(self):
1953
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
1954
 
                              count=3,
1955
 
                              interval=90061,
1956
 
                              dtstart=parse("19970902T090000"))),
1957
 
                         [datetime(1997, 9, 2, 9, 0, 0),
1958
 
                          datetime(1997, 9, 3, 10, 1, 1),
1959
 
                          datetime(1997, 9, 4, 11, 2, 2)])
1960
 
 
1961
 
    def testSecondlyByMonth(self):
1962
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
1963
 
                              count=3,
1964
 
                              bymonth=(1,3),
1965
 
                              dtstart=parse("19970902T090000"))),
1966
 
                         [datetime(1998, 1, 1, 0, 0, 0),
1967
 
                          datetime(1998, 1, 1, 0, 0, 1),
1968
 
                          datetime(1998, 1, 1, 0, 0, 2)])
1969
 
 
1970
 
    def testSecondlyByMonthDay(self):
1971
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
1972
 
                              count=3,
1973
 
                              bymonthday=(1,3),
1974
 
                              dtstart=parse("19970902T090000"))),
1975
 
                         [datetime(1997, 9, 3, 0, 0, 0),
1976
 
                          datetime(1997, 9, 3, 0, 0, 1),
1977
 
                          datetime(1997, 9, 3, 0, 0, 2)])
1978
 
 
1979
 
    def testSecondlyByMonthAndMonthDay(self):
1980
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
1981
 
                              count=3,
1982
 
                              bymonth=(1,3),
1983
 
                              bymonthday=(5,7),
1984
 
                              dtstart=parse("19970902T090000"))),
1985
 
                         [datetime(1998, 1, 5, 0, 0, 0),
1986
 
                          datetime(1998, 1, 5, 0, 0, 1),
1987
 
                          datetime(1998, 1, 5, 0, 0, 2)])
1988
 
 
1989
 
    def testSecondlyByWeekDay(self):
1990
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
1991
 
                              count=3,
1992
 
                              byweekday=(TU,TH),
1993
 
                              dtstart=parse("19970902T090000"))),
1994
 
                         [datetime(1997, 9, 2, 9, 0, 0),
1995
 
                          datetime(1997, 9, 2, 9, 0, 1),
1996
 
                          datetime(1997, 9, 2, 9, 0, 2)])
1997
 
 
1998
 
    def testSecondlyByNWeekDay(self):
1999
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2000
 
                              count=3,
2001
 
                              byweekday=(TU(1),TH(-1)),
2002
 
                              dtstart=parse("19970902T090000"))),
2003
 
                         [datetime(1997, 9, 2, 9, 0, 0),
2004
 
                          datetime(1997, 9, 2, 9, 0, 1),
2005
 
                          datetime(1997, 9, 2, 9, 0, 2)])
2006
 
 
2007
 
    def testSecondlyByMonthAndWeekDay(self):
2008
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2009
 
                              count=3,
2010
 
                              bymonth=(1,3),
2011
 
                              byweekday=(TU,TH),
2012
 
                              dtstart=parse("19970902T090000"))),
2013
 
                         [datetime(1998, 1, 1, 0, 0, 0),
2014
 
                          datetime(1998, 1, 1, 0, 0, 1),
2015
 
                          datetime(1998, 1, 1, 0, 0, 2)])
2016
 
 
2017
 
    def testSecondlyByMonthAndNWeekDay(self):
2018
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2019
 
                              count=3,
2020
 
                              bymonth=(1,3),
2021
 
                              byweekday=(TU(1),TH(-1)),
2022
 
                              dtstart=parse("19970902T090000"))),
2023
 
                         [datetime(1998, 1, 1, 0, 0, 0),
2024
 
                          datetime(1998, 1, 1, 0, 0, 1),
2025
 
                          datetime(1998, 1, 1, 0, 0, 2)])
2026
 
 
2027
 
    def testSecondlyByMonthDayAndWeekDay(self):
2028
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2029
 
                              count=3,
2030
 
                              bymonthday=(1,3),
2031
 
                              byweekday=(TU,TH),
2032
 
                              dtstart=parse("19970902T090000"))),
2033
 
                         [datetime(1998, 1, 1, 0, 0, 0),
2034
 
                          datetime(1998, 1, 1, 0, 0, 1),
2035
 
                          datetime(1998, 1, 1, 0, 0, 2)])
2036
 
 
2037
 
    def testSecondlyByMonthAndMonthDayAndWeekDay(self):
2038
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2039
 
                              count=3,
2040
 
                              bymonth=(1,3),
2041
 
                              bymonthday=(1,3),
2042
 
                              byweekday=(TU,TH),
2043
 
                              dtstart=parse("19970902T090000"))),
2044
 
                         [datetime(1998, 1, 1, 0, 0, 0),
2045
 
                          datetime(1998, 1, 1, 0, 0, 1),
2046
 
                          datetime(1998, 1, 1, 0, 0, 2)])
2047
 
 
2048
 
    def testSecondlyByYearDay(self):
2049
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2050
 
                              count=3,
2051
 
                              byyearday=(1,100,200),
2052
 
                              dtstart=parse("19970902T090000"))),
2053
 
                         [datetime(1998, 1, 1, 0, 0, 0),
2054
 
                          datetime(1998, 1, 1, 0, 0, 1),
2055
 
                          datetime(1998, 1, 1, 0, 0, 2)])
2056
 
 
2057
 
    def testSecondlyByMonthAndYearDay(self):
2058
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2059
 
                              count=3,
2060
 
                              bymonth=(4,7),
2061
 
                              byyearday=(1,100,200),
2062
 
                              dtstart=parse("19970902T090000"))),
2063
 
                         [datetime(1998, 4, 10, 0, 0, 0),
2064
 
                          datetime(1998, 4, 10, 0, 0, 1),
2065
 
                          datetime(1998, 4, 10, 0, 0, 2)])
2066
 
 
2067
 
    def testSecondlyByWeekNo(self):
2068
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2069
 
                              count=3,
2070
 
                              byweekno=20,
2071
 
                              dtstart=parse("19970902T090000"))),
2072
 
                         [datetime(1998, 5, 11, 0, 0, 0),
2073
 
                          datetime(1998, 5, 11, 0, 0, 1),
2074
 
                          datetime(1998, 5, 11, 0, 0, 2)])
2075
 
 
2076
 
    def testSecondlyByWeekNoAndWeekDay(self):
2077
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2078
 
                              count=3,
2079
 
                              byweekno=1,
2080
 
                              byweekday=MO,
2081
 
                              dtstart=parse("19970902T090000"))),
2082
 
                         [datetime(1997, 12, 29, 0, 0, 0),
2083
 
                          datetime(1997, 12, 29, 0, 0, 1),
2084
 
                          datetime(1997, 12, 29, 0, 0, 2)])
2085
 
 
2086
 
    def testSecondlyByWeekNoAndWeekDayLarge(self):
2087
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2088
 
                              count=3,
2089
 
                              byweekno=52,
2090
 
                              byweekday=SU,
2091
 
                              dtstart=parse("19970902T090000"))),
2092
 
                         [datetime(1997, 12, 28, 0, 0, 0),
2093
 
                          datetime(1997, 12, 28, 0, 0, 1),
2094
 
                          datetime(1997, 12, 28, 0, 0, 2)])
2095
 
 
2096
 
    def testSecondlyByWeekNoAndWeekDayLast(self):
2097
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2098
 
                              count=3,
2099
 
                              byweekno=-1,
2100
 
                              byweekday=SU,
2101
 
                              dtstart=parse("19970902T090000"))),
2102
 
                         [datetime(1997, 12, 28, 0, 0, 0),
2103
 
                          datetime(1997, 12, 28, 0, 0, 1),
2104
 
                          datetime(1997, 12, 28, 0, 0, 2)])
2105
 
 
2106
 
    def testSecondlyByWeekNoAndWeekDay53(self):
2107
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2108
 
                              count=3,
2109
 
                              byweekno=53,
2110
 
                              byweekday=MO,
2111
 
                              dtstart=parse("19970902T090000"))),
2112
 
                         [datetime(1998, 12, 28, 0, 0, 0),
2113
 
                          datetime(1998, 12, 28, 0, 0, 1),
2114
 
                          datetime(1998, 12, 28, 0, 0, 2)])
2115
 
 
2116
 
    def testSecondlyByEaster(self):
2117
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2118
 
                              count=3,
2119
 
                              byeaster=0,
2120
 
                              dtstart=parse("19970902T090000"))),
2121
 
                         [datetime(1998, 4, 12, 0, 0, 0),
2122
 
                          datetime(1998, 4, 12, 0, 0, 1),
2123
 
                          datetime(1998, 4, 12, 0, 0, 2)])
2124
 
 
2125
 
    def testSecondlyByEasterPos(self):
2126
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2127
 
                              count=3,
2128
 
                              byeaster=1,
2129
 
                              dtstart=parse("19970902T090000"))),
2130
 
                         [datetime(1998, 4, 13, 0, 0, 0),
2131
 
                          datetime(1998, 4, 13, 0, 0, 1),
2132
 
                          datetime(1998, 4, 13, 0, 0, 2)])
2133
 
 
2134
 
    def testSecondlyByEasterNeg(self):
2135
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2136
 
                              count=3,
2137
 
                              byeaster=-1,
2138
 
                              dtstart=parse("19970902T090000"))),
2139
 
                         [datetime(1998, 4, 11, 0, 0, 0),
2140
 
                          datetime(1998, 4, 11, 0, 0, 1),
2141
 
                          datetime(1998, 4, 11, 0, 0, 2)])
2142
 
 
2143
 
    def testSecondlyByHour(self):
2144
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2145
 
                              count=3,
2146
 
                              byhour=(6,18),
2147
 
                              dtstart=parse("19970902T090000"))),
2148
 
                         [datetime(1997, 9, 2, 18, 0, 0),
2149
 
                          datetime(1997, 9, 2, 18, 0, 1),
2150
 
                          datetime(1997, 9, 2, 18, 0, 2)])
2151
 
 
2152
 
    def testSecondlyByMinute(self):
2153
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2154
 
                              count=3,
2155
 
                              byminute=(6,18),
2156
 
                              dtstart=parse("19970902T090000"))),
2157
 
                         [datetime(1997, 9, 2, 9, 6, 0),
2158
 
                          datetime(1997, 9, 2, 9, 6, 1),
2159
 
                          datetime(1997, 9, 2, 9, 6, 2)])
2160
 
 
2161
 
    def testSecondlyBySecond(self):
2162
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2163
 
                              count=3,
2164
 
                              bysecond=(6,18),
2165
 
                              dtstart=parse("19970902T090000"))),
2166
 
                         [datetime(1997, 9, 2, 9, 0, 6),
2167
 
                          datetime(1997, 9, 2, 9, 0, 18),
2168
 
                          datetime(1997, 9, 2, 9, 1, 6)])
2169
 
 
2170
 
    def testSecondlyByHourAndMinute(self):
2171
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2172
 
                              count=3,
2173
 
                              byhour=(6,18),
2174
 
                              byminute=(6,18),
2175
 
                              dtstart=parse("19970902T090000"))),
2176
 
                         [datetime(1997, 9, 2, 18, 6, 0),
2177
 
                          datetime(1997, 9, 2, 18, 6, 1),
2178
 
                          datetime(1997, 9, 2, 18, 6, 2)])
2179
 
 
2180
 
    def testSecondlyByHourAndSecond(self):
2181
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2182
 
                              count=3,
2183
 
                              byhour=(6,18),
2184
 
                              bysecond=(6,18),
2185
 
                              dtstart=parse("19970902T090000"))),
2186
 
                         [datetime(1997, 9, 2, 18, 0, 6),
2187
 
                          datetime(1997, 9, 2, 18, 0, 18),
2188
 
                          datetime(1997, 9, 2, 18, 1, 6)])
2189
 
 
2190
 
    def testSecondlyByMinuteAndSecond(self):
2191
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2192
 
                              count=3,
2193
 
                              byminute=(6,18),
2194
 
                              bysecond=(6,18),
2195
 
                              dtstart=parse("19970902T090000"))),
2196
 
                         [datetime(1997, 9, 2, 9, 6, 6),
2197
 
                          datetime(1997, 9, 2, 9, 6, 18),
2198
 
                          datetime(1997, 9, 2, 9, 18, 6)])
2199
 
 
2200
 
    def testSecondlyByHourAndMinuteAndSecond(self):
2201
 
        self.assertEqual(list(rrule(FREQ_SECONDLY,
2202
 
                              count=3,
2203
 
                              byhour=(6,18),
2204
 
                              byminute=(6,18),
2205
 
                              bysecond=(6,18),
2206
 
                              dtstart=parse("19970902T090000"))),
2207
 
                         [datetime(1997, 9, 2, 18, 6, 6),
2208
 
                          datetime(1997, 9, 2, 18, 6, 18),
2209
 
                          datetime(1997, 9, 2, 18, 18, 6)])
2210
 
 
2211
 
    def testUntilNotMatching(self):
2212
 
        self.assertEqual(list(rrule(FREQ_DAILY,
2213
 
                              count=3,
2214
 
                              dtstart=parse("19970902T090000"),
2215
 
                              until=parse("19970905T080000"))),
2216
 
                         [datetime(1997, 9, 2, 9, 0),
2217
 
                          datetime(1997, 9, 3, 9, 0),
2218
 
                          datetime(1997, 9, 4, 9, 0)])
2219
 
 
2220
 
    def testUntilMatching(self):
2221
 
        self.assertEqual(list(rrule(FREQ_DAILY,
2222
 
                              count=3,
2223
 
                              dtstart=parse("19970902T090000"),
2224
 
                              until=parse("19970904T090000"))),
2225
 
                         [datetime(1997, 9, 2, 9, 0),
2226
 
                          datetime(1997, 9, 3, 9, 0),
2227
 
                          datetime(1997, 9, 4, 9, 0)])
2228
 
 
2229
 
    def testUntilSingle(self):
2230
 
        self.assertEqual(list(rrule(FREQ_DAILY,
2231
 
                              count=3,
2232
 
                              dtstart=parse("19970902T090000"),
2233
 
                              until=parse("19970902T090000"))),
2234
 
                         [datetime(1997, 9, 2, 9, 0)])
2235
 
 
2236
 
    def testUntilEmpty(self):
2237
 
        self.assertEqual(list(rrule(FREQ_DAILY,
2238
 
                              count=3,
2239
 
                              dtstart=parse("19970902T090000"),
2240
 
                              until=parse("19970901T090000"))),
2241
 
                         [])
2242
 
 
2243
 
    def testUntilWithDate(self):
2244
 
        self.assertEqual(list(rrule(FREQ_DAILY,
2245
 
                              count=3,
2246
 
                              dtstart=parse("19970902T090000"),
2247
 
                              until=date(1997, 9, 5))),
2248
 
                         [datetime(1997, 9, 2, 9, 0),
2249
 
                          datetime(1997, 9, 3, 9, 0),
2250
 
                          datetime(1997, 9, 4, 9, 0)])
2251
 
 
2252
 
    def testWkStIntervalMO(self):
2253
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
2254
 
                              count=3,
2255
 
                              interval=2,
2256
 
                              byweekday=(TU,SU),
2257
 
                              wkst=MO,
2258
 
                              dtstart=parse("19970902T090000"))),
2259
 
                         [datetime(1997, 9, 2, 9, 0),
2260
 
                          datetime(1997, 9, 7, 9, 0),
2261
 
                          datetime(1997, 9, 16, 9, 0)])
2262
 
 
2263
 
    def testWkStIntervalSU(self):
2264
 
        self.assertEqual(list(rrule(FREQ_WEEKLY,
2265
 
                              count=3,
2266
 
                              interval=2,
2267
 
                              byweekday=(TU,SU),
2268
 
                              wkst=SU,
2269
 
                              dtstart=parse("19970902T090000"))),
2270
 
                         [datetime(1997, 9, 2, 9, 0),
2271
 
                          datetime(1997, 9, 14, 9, 0),
2272
 
                          datetime(1997, 9, 16, 9, 0)])
2273
 
 
2274
 
    def testDTStartIsDate(self):
2275
 
        self.assertEqual(list(rrule(FREQ_DAILY,
2276
 
                              count=3,
2277
 
                              dtstart=date(1997, 9, 2))),
2278
 
                         [datetime(1997, 9, 2, 0, 0),
2279
 
                          datetime(1997, 9, 3, 0, 0),
2280
 
                          datetime(1997, 9, 4, 0, 0)])
2281
 
 
2282
 
    def testDTStartWithMicroseconds(self):
2283
 
        self.assertEqual(list(rrule(FREQ_DAILY,
2284
 
                              count=3,
2285
 
                              dtstart=parse("19970902T090000.5"))),
2286
 
                         [datetime(1997, 9, 2, 9, 0),
2287
 
                          datetime(1997, 9, 3, 9, 0),
2288
 
                          datetime(1997, 9, 4, 9, 0)])
2289
 
 
2290
 
    def testMaxYear(self):
2291
 
        self.assertEqual(list(rrule(FREQ_YEARLY,
2292
 
                              count=3,
2293
 
                              bymonth=2,
2294
 
                              bymonthday=31,
2295
 
                              dtstart=parse("99970902T090000"))),
2296
 
                         [])
2297
 
 
2298
 
    def testGetItem(self):
2299
 
        self.assertEqual(rrule(FREQ_DAILY,
2300
 
                               count=3,
2301
 
                               dtstart=parse("19970902T090000"))[0],
2302
 
                         datetime(1997, 9, 2, 9, 0))
2303
 
 
2304
 
    def testGetItemNeg(self):
2305
 
        self.assertEqual(rrule(FREQ_DAILY,
2306
 
                               count=3,
2307
 
                               dtstart=parse("19970902T090000"))[-1],
2308
 
                         datetime(1997, 9, 4, 9, 0))
2309
 
 
2310
 
    def testGetItemSlice(self):
2311
 
        self.assertEqual(rrule(FREQ_DAILY,
2312
 
                               #count=3,
2313
 
                               dtstart=parse("19970902T090000"))[1:2],
2314
 
                         [datetime(1997, 9, 3, 9, 0)])
2315
 
 
2316
 
    def testGetItemSliceEmpty(self):
2317
 
        self.assertEqual(rrule(FREQ_DAILY,
2318
 
                               count=3,
2319
 
                               dtstart=parse("19970902T090000"))[:],
2320
 
                         [datetime(1997, 9, 2, 9, 0),
2321
 
                          datetime(1997, 9, 3, 9, 0),
2322
 
                          datetime(1997, 9, 4, 9, 0)])
2323
 
 
2324
 
    def testGetItemSliceStep(self):
2325
 
        self.assertEqual(rrule(FREQ_DAILY,
2326
 
                               count=3,
2327
 
                               dtstart=parse("19970902T090000"))[::-2],
2328
 
                         [datetime(1997, 9, 4, 9, 0),
2329
 
                          datetime(1997, 9, 2, 9, 0)])
2330
 
 
2331
 
    def testCount(self):
2332
 
        self.assertEqual(rrule(FREQ_DAILY,
2333
 
                               count=3,
2334
 
                               dtstart=parse("19970902T090000")).count(),
2335
 
                         3)
2336
 
 
2337
 
    def testContains(self):
2338
 
        rr = rrule(FREQ_DAILY, count=3, dtstart=parse("19970902T090000"))
2339
 
        self.assertEqual(datetime(1997, 9, 3, 9, 0) in rr, True)
2340
 
 
2341
 
    def testContainsNot(self):
2342
 
        rr = rrule(FREQ_DAILY, count=3, dtstart=parse("19970902T090000"))
2343
 
        self.assertEqual(datetime(1997, 9, 3, 9, 0) not in rr, False)
2344
 
 
2345
 
    def testBefore(self):
2346
 
        self.assertEqual(rrule(FREQ_DAILY,
2347
 
                               #count=5,
2348
 
                               dtstart=parse("19970902T090000"))
2349
 
                               .before(parse("19970905T090000")),
2350
 
                         datetime(1997, 9, 4, 9, 0))
2351
 
 
2352
 
    def testBeforeInc(self):
2353
 
        self.assertEqual(rrule(FREQ_DAILY,
2354
 
                               #count=5,
2355
 
                               dtstart=parse("19970902T090000"))
2356
 
                               .before(parse("19970905T090000"), inc=True),
2357
 
                         datetime(1997, 9, 5, 9, 0))
2358
 
 
2359
 
    def testAfter(self):
2360
 
        self.assertEqual(rrule(FREQ_DAILY,
2361
 
                               #count=5,
2362
 
                               dtstart=parse("19970902T090000"))
2363
 
                               .after(parse("19970904T090000")),
2364
 
                         datetime(1997, 9, 5, 9, 0))
2365
 
 
2366
 
    def testAfterInc(self):
2367
 
        self.assertEqual(rrule(FREQ_DAILY,
2368
 
                               #count=5,
2369
 
                               dtstart=parse("19970902T090000"))
2370
 
                               .after(parse("19970904T090000"), inc=True),
2371
 
                         datetime(1997, 9, 4, 9, 0))
2372
 
 
2373
 
    def testBetween(self):
2374
 
        self.assertEqual(rrule(FREQ_DAILY,
2375
 
                               #count=5,
2376
 
                               dtstart=parse("19970902T090000"))
2377
 
                               .between(parse("19970902T090000"),
2378
 
                                        parse("19970906T090000")),
2379
 
                         [datetime(1997, 9, 3, 9, 0),
2380
 
                          datetime(1997, 9, 4, 9, 0),
2381
 
                          datetime(1997, 9, 5, 9, 0)])
2382
 
 
2383
 
    def testBetweenInc(self):
2384
 
        self.assertEqual(rrule(FREQ_DAILY,
2385
 
                               #count=5,
2386
 
                               dtstart=parse("19970902T090000"))
2387
 
                               .between(parse("19970902T090000"),
2388
 
                                        parse("19970906T090000"), inc=True),
2389
 
                         [datetime(1997, 9, 2, 9, 0),
2390
 
                          datetime(1997, 9, 3, 9, 0),
2391
 
                          datetime(1997, 9, 4, 9, 0),
2392
 
                          datetime(1997, 9, 5, 9, 0),
2393
 
                          datetime(1997, 9, 6, 9, 0)])
2394
 
 
2395
 
    def testCachePre(self):
2396
 
        rr = rrule(FREQ_DAILY, count=15, cache=True,
2397
 
                   dtstart=parse("19970902T090000"))
2398
 
        self.assertEqual(list(rr),
2399
 
                         [datetime(1997, 9, 2, 9, 0),
2400
 
                          datetime(1997, 9, 3, 9, 0),
2401
 
                          datetime(1997, 9, 4, 9, 0),
2402
 
                          datetime(1997, 9, 5, 9, 0),
2403
 
                          datetime(1997, 9, 6, 9, 0),
2404
 
                          datetime(1997, 9, 7, 9, 0),
2405
 
                          datetime(1997, 9, 8, 9, 0),
2406
 
                          datetime(1997, 9, 9, 9, 0),
2407
 
                          datetime(1997, 9, 10, 9, 0),
2408
 
                          datetime(1997, 9, 11, 9, 0),
2409
 
                          datetime(1997, 9, 12, 9, 0),
2410
 
                          datetime(1997, 9, 13, 9, 0),
2411
 
                          datetime(1997, 9, 14, 9, 0),
2412
 
                          datetime(1997, 9, 15, 9, 0),
2413
 
                          datetime(1997, 9, 16, 9, 0)])
2414
 
 
2415
 
    def testCachePost(self):
2416
 
        rr = rrule(FREQ_DAILY, count=15, cache=True,
2417
 
                   dtstart=parse("19970902T090000"))
2418
 
        for x in rr: pass
2419
 
        self.assertEqual(list(rr),
2420
 
                         [datetime(1997, 9, 2, 9, 0),
2421
 
                          datetime(1997, 9, 3, 9, 0),
2422
 
                          datetime(1997, 9, 4, 9, 0),
2423
 
                          datetime(1997, 9, 5, 9, 0),
2424
 
                          datetime(1997, 9, 6, 9, 0),
2425
 
                          datetime(1997, 9, 7, 9, 0),
2426
 
                          datetime(1997, 9, 8, 9, 0),
2427
 
                          datetime(1997, 9, 9, 9, 0),
2428
 
                          datetime(1997, 9, 10, 9, 0),
2429
 
                          datetime(1997, 9, 11, 9, 0),
2430
 
                          datetime(1997, 9, 12, 9, 0),
2431
 
                          datetime(1997, 9, 13, 9, 0),
2432
 
                          datetime(1997, 9, 14, 9, 0),
2433
 
                          datetime(1997, 9, 15, 9, 0),
2434
 
                          datetime(1997, 9, 16, 9, 0)])
2435
 
 
2436
 
    def testCachePostInternal(self):
2437
 
        rr = rrule(FREQ_DAILY, count=15, cache=True,
2438
 
                   dtstart=parse("19970902T090000"))
2439
 
        for x in rr: pass
2440
 
        self.assertEqual(rr._cache,
2441
 
                         [datetime(1997, 9, 2, 9, 0),
2442
 
                          datetime(1997, 9, 3, 9, 0),
2443
 
                          datetime(1997, 9, 4, 9, 0),
2444
 
                          datetime(1997, 9, 5, 9, 0),
2445
 
                          datetime(1997, 9, 6, 9, 0),
2446
 
                          datetime(1997, 9, 7, 9, 0),
2447
 
                          datetime(1997, 9, 8, 9, 0),
2448
 
                          datetime(1997, 9, 9, 9, 0),
2449
 
                          datetime(1997, 9, 10, 9, 0),
2450
 
                          datetime(1997, 9, 11, 9, 0),
2451
 
                          datetime(1997, 9, 12, 9, 0),
2452
 
                          datetime(1997, 9, 13, 9, 0),
2453
 
                          datetime(1997, 9, 14, 9, 0),
2454
 
                          datetime(1997, 9, 15, 9, 0),
2455
 
                          datetime(1997, 9, 16, 9, 0)])
2456
 
 
2457
 
    def testCachePreContains(self):
2458
 
        rr = rrule(FREQ_DAILY, count=3, cache=True,
2459
 
                   dtstart=parse("19970902T090000"))
2460
 
        self.assertEqual(datetime(1997, 9, 3, 9, 0) in rr, True)
2461
 
 
2462
 
    def testCachePostContains(self):
2463
 
        rr = rrule(FREQ_DAILY, count=3, cache=True,
2464
 
                   dtstart=parse("19970902T090000"))
2465
 
        for x in rr: pass
2466
 
        self.assertEqual(datetime(1997, 9, 3, 9, 0) in rr, True)
2467
 
 
2468
 
    def testSet(self):
2469
 
        set = rruleset()
2470
 
        set.rrule(rrule(FREQ_YEARLY, count=2, byweekday=TU,
2471
 
                        dtstart=parse("19970902T090000")))
2472
 
        set.rrule(rrule(FREQ_YEARLY, count=1, byweekday=TH,
2473
 
                        dtstart=parse("19970902T090000")))
2474
 
        self.assertEqual(list(set),
2475
 
                         [datetime(1997, 9, 2, 9, 0),
2476
 
                          datetime(1997, 9, 4, 9, 0),
2477
 
                          datetime(1997, 9, 9, 9, 0)])
2478
 
 
2479
 
    def testSetDate(self):
2480
 
        set = rruleset()
2481
 
        set.rrule(rrule(FREQ_YEARLY, count=1, byweekday=TU,
2482
 
                        dtstart=parse("19970902T090000")))
2483
 
        set.rdate(datetime(1997, 9, 4, 9))
2484
 
        set.rdate(datetime(1997, 9, 9, 9))
2485
 
        self.assertEqual(list(set),
2486
 
                         [datetime(1997, 9, 2, 9, 0),
2487
 
                          datetime(1997, 9, 4, 9, 0),
2488
 
                          datetime(1997, 9, 9, 9, 0)])
2489
 
 
2490
 
    def testSetExRule(self):
2491
 
        set = rruleset()
2492
 
        set.rrule(rrule(FREQ_YEARLY, count=6, byweekday=(TU,TH),
2493
 
                        dtstart=parse("19970902T090000")))
2494
 
        set.exrule(rrule(FREQ_YEARLY, count=3, byweekday=TH,
2495
 
                        dtstart=parse("19970902T090000")))
2496
 
        self.assertEqual(list(set),
2497
 
                         [datetime(1997, 9, 2, 9, 0),
2498
 
                          datetime(1997, 9, 9, 9, 0),
2499
 
                          datetime(1997, 9, 16, 9, 0)])
2500
 
 
2501
 
    def testSetExDate(self):
2502
 
        set = rruleset()
2503
 
        set.rrule(rrule(FREQ_YEARLY, count=6, byweekday=(TU,TH),
2504
 
                        dtstart=parse("19970902T090000")))
2505
 
        set.exdate(datetime(1997, 9, 4, 9))
2506
 
        set.exdate(datetime(1997, 9, 11, 9))
2507
 
        set.exdate(datetime(1997, 9, 18, 9))
2508
 
        self.assertEqual(list(set),
2509
 
                         [datetime(1997, 9, 2, 9, 0),
2510
 
                          datetime(1997, 9, 9, 9, 0),
2511
 
                          datetime(1997, 9, 16, 9, 0)])
2512
 
 
2513
 
    def testSetDateAndExDate(self):
2514
 
        set = rruleset()
2515
 
        set.rdate(datetime(1997, 9, 2, 9))
2516
 
        set.rdate(datetime(1997, 9, 4, 9))
2517
 
        set.rdate(datetime(1997, 9, 9, 9))
2518
 
        set.rdate(datetime(1997, 9, 11, 9))
2519
 
        set.rdate(datetime(1997, 9, 16, 9))
2520
 
        set.rdate(datetime(1997, 9, 18, 9))
2521
 
        set.exdate(datetime(1997, 9, 4, 9))
2522
 
        set.exdate(datetime(1997, 9, 11, 9))
2523
 
        set.exdate(datetime(1997, 9, 18, 9))
2524
 
        self.assertEqual(list(set),
2525
 
                         [datetime(1997, 9, 2, 9, 0),
2526
 
                          datetime(1997, 9, 9, 9, 0),
2527
 
                          datetime(1997, 9, 16, 9, 0)])
2528
 
 
2529
 
    def testSetDateAndExRule(self):
2530
 
        set = rruleset()
2531
 
        set.rdate(datetime(1997, 9, 2, 9))
2532
 
        set.rdate(datetime(1997, 9, 4, 9))
2533
 
        set.rdate(datetime(1997, 9, 9, 9))
2534
 
        set.rdate(datetime(1997, 9, 11, 9))
2535
 
        set.rdate(datetime(1997, 9, 16, 9))
2536
 
        set.rdate(datetime(1997, 9, 18, 9))
2537
 
        set.exrule(rrule(FREQ_YEARLY, count=3, byweekday=TH,
2538
 
                        dtstart=parse("19970902T090000")))
2539
 
        self.assertEqual(list(set),
2540
 
                         [datetime(1997, 9, 2, 9, 0),
2541
 
                          datetime(1997, 9, 9, 9, 0),
2542
 
                          datetime(1997, 9, 16, 9, 0)])
2543
 
 
2544
 
    def testSetCount(self):
2545
 
        set = rruleset()
2546
 
        set.rrule(rrule(FREQ_YEARLY, count=6, byweekday=(TU,TH),
2547
 
                        dtstart=parse("19970902T090000")))
2548
 
        set.exrule(rrule(FREQ_YEARLY, count=3, byweekday=TH,
2549
 
                        dtstart=parse("19970902T090000")))
2550
 
        self.assertEqual(set.count(), 3)
2551
 
 
2552
 
    def testSetCachePre(self):
2553
 
        set = rruleset()
2554
 
        set.rrule(rrule(FREQ_YEARLY, count=2, byweekday=TU,
2555
 
                        dtstart=parse("19970902T090000")))
2556
 
        set.rrule(rrule(FREQ_YEARLY, count=1, byweekday=TH,
2557
 
                        dtstart=parse("19970902T090000")))
2558
 
        self.assertEqual(list(set),
2559
 
                         [datetime(1997, 9, 2, 9, 0),
2560
 
                          datetime(1997, 9, 4, 9, 0),
2561
 
                          datetime(1997, 9, 9, 9, 0)])
2562
 
 
2563
 
    def testSetCachePost(self):
2564
 
        set = rruleset(cache=True)
2565
 
        set.rrule(rrule(FREQ_YEARLY, count=2, byweekday=TU,
2566
 
                        dtstart=parse("19970902T090000")))
2567
 
        set.rrule(rrule(FREQ_YEARLY, count=1, byweekday=TH,
2568
 
                        dtstart=parse("19970902T090000")))
2569
 
        for x in set: pass
2570
 
        self.assertEqual(list(set),
2571
 
                         [datetime(1997, 9, 2, 9, 0),
2572
 
                          datetime(1997, 9, 4, 9, 0),
2573
 
                          datetime(1997, 9, 9, 9, 0)])
2574
 
 
2575
 
    def testSetCachePostInternal(self):
2576
 
        set = rruleset(cache=True)
2577
 
        set.rrule(rrule(FREQ_YEARLY, count=2, byweekday=TU,
2578
 
                        dtstart=parse("19970902T090000")))
2579
 
        set.rrule(rrule(FREQ_YEARLY, count=1, byweekday=TH,
2580
 
                        dtstart=parse("19970902T090000")))
2581
 
        for x in set: pass
2582
 
        self.assertEqual(list(set._cache),
2583
 
                         [datetime(1997, 9, 2, 9, 0),
2584
 
                          datetime(1997, 9, 4, 9, 0),
2585
 
                          datetime(1997, 9, 9, 9, 0)])
2586
 
 
2587
 
    def testStr(self):
2588
 
        self.assertEqual(list(rrulestr(
2589
 
                              "DTSTART:19970902T090000\n"
2590
 
                              "RRULE:FREQ=YEARLY;COUNT=3\n"
2591
 
                              )),
2592
 
                         [datetime(1997, 9, 2, 9, 0),
2593
 
                          datetime(1998, 9, 2, 9, 0),
2594
 
                          datetime(1999, 9, 2, 9, 0)])
2595
 
 
2596
 
    def testStrType(self):
2597
 
        self.assertEqual(isinstance(rrulestr(
2598
 
                              "DTSTART:19970902T090000\n"
2599
 
                              "RRULE:FREQ=YEARLY;COUNT=3\n"
2600
 
                              ), rrule), True)
2601
 
 
2602
 
    def testStrForceSetType(self):
2603
 
        self.assertEqual(isinstance(rrulestr(
2604
 
                              "DTSTART:19970902T090000\n"
2605
 
                              "RRULE:FREQ=YEARLY;COUNT=3\n"
2606
 
                              , forceset=True), rruleset), True)
2607
 
 
2608
 
    def testStrSetType(self):
2609
 
        self.assertEqual(isinstance(rrulestr(
2610
 
                              "DTSTART:19970902T090000\n"
2611
 
                              "RRULE:FREQ=YEARLY;COUNT=2;BYDAY=TU\n"
2612
 
                              "RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TH\n"
2613
 
                              ), rruleset), True)
2614
 
 
2615
 
    def testStrCase(self):
2616
 
        self.assertEqual(list(rrulestr(
2617
 
                              "dtstart:19970902T090000\n"
2618
 
                              "rrule:freq=yearly;count=3\n"
2619
 
                              )),
2620
 
                         [datetime(1997, 9, 2, 9, 0),
2621
 
                          datetime(1998, 9, 2, 9, 0),
2622
 
                          datetime(1999, 9, 2, 9, 0)])
2623
 
 
2624
 
    def testStrSpaces(self):
2625
 
        self.assertEqual(list(rrulestr(
2626
 
                              " DTSTART:19970902T090000 "
2627
 
                              " RRULE:FREQ=YEARLY;COUNT=3 "
2628
 
                              )),
2629
 
                         [datetime(1997, 9, 2, 9, 0),
2630
 
                          datetime(1998, 9, 2, 9, 0),
2631
 
                          datetime(1999, 9, 2, 9, 0)])
2632
 
 
2633
 
    def testStrSpacesAndLines(self):
2634
 
        self.assertEqual(list(rrulestr(
2635
 
                              " DTSTART:19970902T090000 \n"
2636
 
                              " \n"
2637
 
                              " RRULE:FREQ=YEARLY;COUNT=3 \n"
2638
 
                              )),
2639
 
                         [datetime(1997, 9, 2, 9, 0),
2640
 
                          datetime(1998, 9, 2, 9, 0),
2641
 
                          datetime(1999, 9, 2, 9, 0)])
2642
 
 
2643
 
    def testStrNoDTStart(self):
2644
 
        self.assertEqual(list(rrulestr(
2645
 
                              "RRULE:FREQ=YEARLY;COUNT=3\n"
2646
 
                              , dtstart=parse("19970902T090000"))),
2647
 
                         [datetime(1997, 9, 2, 9, 0),
2648
 
                          datetime(1998, 9, 2, 9, 0),
2649
 
                          datetime(1999, 9, 2, 9, 0)])
2650
 
 
2651
 
    def testStrValueOnly(self):
2652
 
        self.assertEqual(list(rrulestr(
2653
 
                              "FREQ=YEARLY;COUNT=3\n"
2654
 
                              , dtstart=parse("19970902T090000"))),
2655
 
                         [datetime(1997, 9, 2, 9, 0),
2656
 
                          datetime(1998, 9, 2, 9, 0),
2657
 
                          datetime(1999, 9, 2, 9, 0)])
2658
 
 
2659
 
    def testStrUnfold(self):
2660
 
        self.assertEqual(list(rrulestr(
2661
 
                              "FREQ=YEA\n RLY;COUNT=3\n", unfold=True,
2662
 
                              dtstart=parse("19970902T090000"))),
2663
 
                         [datetime(1997, 9, 2, 9, 0),
2664
 
                          datetime(1998, 9, 2, 9, 0),
2665
 
                          datetime(1999, 9, 2, 9, 0)])
2666
 
 
2667
 
    def testStrSet(self):
2668
 
        self.assertEqual(list(rrulestr(
2669
 
                              "DTSTART:19970902T090000\n"
2670
 
                              "RRULE:FREQ=YEARLY;COUNT=2;BYDAY=TU\n"
2671
 
                              "RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TH\n"
2672
 
                              )),
2673
 
                         [datetime(1997, 9, 2, 9, 0),
2674
 
                          datetime(1997, 9, 4, 9, 0),
2675
 
                          datetime(1997, 9, 9, 9, 0)])
2676
 
 
2677
 
    def testStrSetDate(self):
2678
 
        self.assertEqual(list(rrulestr(
2679
 
                              "DTSTART:19970902T090000\n"
2680
 
                              "RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TU\n"
2681
 
                              "RDATE:19970904T090000\n"
2682
 
                              "RDATE:19970909T090000\n"
2683
 
                              )),
2684
 
                         [datetime(1997, 9, 2, 9, 0),
2685
 
                          datetime(1997, 9, 4, 9, 0),
2686
 
                          datetime(1997, 9, 9, 9, 0)])
2687
 
 
2688
 
    def testStrSetExRule(self):
2689
 
        self.assertEqual(list(rrulestr(
2690
 
                              "DTSTART:19970902T090000\n"
2691
 
                              "RRULE:FREQ=YEARLY;COUNT=6;BYDAY=TU,TH\n"
2692
 
                              "EXRULE:FREQ=YEARLY;COUNT=3;BYDAY=TH\n"
2693
 
                              )),
2694
 
                         [datetime(1997, 9, 2, 9, 0),
2695
 
                          datetime(1997, 9, 9, 9, 0),
2696
 
                          datetime(1997, 9, 16, 9, 0)])
2697
 
 
2698
 
    def testStrSetExDate(self):
2699
 
        self.assertEqual(list(rrulestr(
2700
 
                              "DTSTART:19970902T090000\n"
2701
 
                              "RRULE:FREQ=YEARLY;COUNT=6;BYDAY=TU,TH\n"
2702
 
                              "EXDATE:19970904T090000\n"
2703
 
                              "EXDATE:19970911T090000\n"
2704
 
                              "EXDATE:19970918T090000\n"
2705
 
                              )),
2706
 
                         [datetime(1997, 9, 2, 9, 0),
2707
 
                          datetime(1997, 9, 9, 9, 0),
2708
 
                          datetime(1997, 9, 16, 9, 0)])
2709
 
 
2710
 
    def testStrSetDateAndExDate(self):
2711
 
        self.assertEqual(list(rrulestr(
2712
 
                              "DTSTART:19970902T090000\n"
2713
 
                              "RDATE:19970902T090000\n"
2714
 
                              "RDATE:19970904T090000\n"
2715
 
                              "RDATE:19970909T090000\n"
2716
 
                              "RDATE:19970911T090000\n"
2717
 
                              "RDATE:19970916T090000\n"
2718
 
                              "RDATE:19970918T090000\n"
2719
 
                              "EXDATE:19970904T090000\n"
2720
 
                              "EXDATE:19970911T090000\n"
2721
 
                              "EXDATE:19970918T090000\n"
2722
 
                              )),
2723
 
                         [datetime(1997, 9, 2, 9, 0),
2724
 
                          datetime(1997, 9, 9, 9, 0),
2725
 
                          datetime(1997, 9, 16, 9, 0)])
2726
 
 
2727
 
    def testStrSetDateAndExRule(self):
2728
 
        self.assertEqual(list(rrulestr(
2729
 
                              "DTSTART:19970902T090000\n"
2730
 
                              "RDATE:19970902T090000\n"
2731
 
                              "RDATE:19970904T090000\n"
2732
 
                              "RDATE:19970909T090000\n"
2733
 
                              "RDATE:19970911T090000\n"
2734
 
                              "RDATE:19970916T090000\n"
2735
 
                              "RDATE:19970918T090000\n"
2736
 
                              "EXRULE:FREQ=YEARLY;COUNT=3;BYDAY=TH\n"
2737
 
                              )),
2738
 
                         [datetime(1997, 9, 2, 9, 0),
2739
 
                          datetime(1997, 9, 9, 9, 0),
2740
 
                          datetime(1997, 9, 16, 9, 0)])
2741
 
 
2742
 
    def testStrKeywords(self):
2743
 
        self.assertEqual(list(rrulestr(
2744
 
                              "DTSTART:19970902T090000\n"
2745
 
                              "RRULE:FREQ=YEARLY;COUNT=3;INTERVAL=3;"
2746
 
                                    "BYMONTH=3;BYWEEKDAY=TH;BYMONTHDAY=3;"
2747
 
                                    "BYHOUR=3;BYMINUTE=3;BYSECOND=3\n"
2748
 
                              )),
2749
 
                         [datetime(2033, 3, 3, 3, 3, 3),
2750
 
                          datetime(2039, 3, 3, 3, 3, 3),
2751
 
                          datetime(2072, 3, 3, 3, 3, 3)])
2752
 
 
2753
 
    def testStrNWeekDay(self):
2754
 
        self.assertEqual(list(rrulestr(
2755
 
                              "DTSTART:19970902T090000\n"
2756
 
                              "RRULE:FREQ=YEARLY;COUNT=3;BYDAY=1TU,-1TH\n"
2757
 
                              )),
2758
 
                         [datetime(1997, 12, 25, 9, 0),
2759
 
                          datetime(1998, 1, 6, 9, 0),
2760
 
                          datetime(1998, 12, 31, 9, 0)])
2761
 
 
2762
 
 
2763
 
 
2764
 
class ParserTest(unittest.TestCase):
2765
 
    def setUp(self):
2766
 
        self.tzinfos = {"BRST": -10800}
2767
 
        self.brsttz = tzoffset("BRST", -10800)
2768
 
        self.default = datetime(2003, 9, 25)
2769
 
 
2770
 
    def testDateCommandFormat(self):
2771
 
        self.assertEqual(parse("Thu Sep 25 10:36:28 BRST 2003",
2772
 
                               tzinfos=self.tzinfos),
2773
 
                         datetime(2003, 9, 25, 10, 36, 28,
2774
 
                                  tzinfo=self.brsttz))
2775
 
 
2776
 
    def testDateCommandFormatReversed(self):
2777
 
        self.assertEqual(parse("2003 10:36:28 BRST 25 Sep Thu",
2778
 
                               tzinfos=self.tzinfos),
2779
 
                         datetime(2003, 9, 25, 10, 36, 28,
2780
 
                                  tzinfo=self.brsttz))
2781
 
 
2782
 
    def testDateCommandFormatIgnoreTz(self):
2783
 
        self.assertEqual(parse("Thu Sep 25 10:36:28 BRST 2003",
2784
 
                               ignoretz=True),
2785
 
                         datetime(2003, 9, 25, 10, 36, 28))
2786
 
 
2787
 
    def testDateCommandFormatStrip1(self):
2788
 
        self.assertEqual(parse("Thu Sep 25 10:36:28 2003"),
2789
 
                         datetime(2003, 9, 25, 10, 36, 28))
2790
 
 
2791
 
    def testDateCommandFormatStrip2(self):
2792
 
        self.assertEqual(parse("Thu Sep 25 10:36:28", default=self.default),
2793
 
                         datetime(2003, 9, 25, 10, 36, 28))
2794
 
 
2795
 
    def testDateCommandFormatStrip3(self):
2796
 
        self.assertEqual(parse("Thu Sep 10:36:28", default=self.default),
2797
 
                         datetime(2003, 9, 25, 10, 36, 28))
2798
 
 
2799
 
    def testDateCommandFormatStrip4(self):
2800
 
        self.assertEqual(parse("Thu 10:36:28", default=self.default),
2801
 
                         datetime(2003, 9, 25, 10, 36, 28))
2802
 
 
2803
 
    def testDateCommandFormatStrip5(self):
2804
 
        self.assertEqual(parse("Sep 10:36:28", default=self.default),
2805
 
                         datetime(2003, 9, 25, 10, 36, 28))
2806
 
 
2807
 
    def testDateCommandFormatStrip6(self):
2808
 
        self.assertEqual(parse("10:36:28", default=self.default),
2809
 
                         datetime(2003, 9, 25, 10, 36, 28))
2810
 
 
2811
 
    def testDateCommandFormatStrip7(self):
2812
 
        self.assertEqual(parse("10:36", default=self.default),
2813
 
                         datetime(2003, 9, 25, 10, 36))
2814
 
 
2815
 
    def testDateCommandFormatStrip8(self):
2816
 
        self.assertEqual(parse("Thu Sep 25 2003"),
2817
 
                         datetime(2003, 9, 25))
2818
 
 
2819
 
    def testDateCommandFormatStrip9(self):
2820
 
        self.assertEqual(parse("Sep 25 2003"),
2821
 
                         datetime(2003, 9, 25))
2822
 
 
2823
 
    def testDateCommandFormatStrip9(self):
2824
 
        self.assertEqual(parse("Sep 2003", default=self.default),
2825
 
                         datetime(2003, 9, 25))
2826
 
 
2827
 
    def testDateCommandFormatStrip10(self):
2828
 
        self.assertEqual(parse("Sep", default=self.default),
2829
 
                         datetime(2003, 9, 25))
2830
 
 
2831
 
    def testDateCommandFormatStrip11(self):
2832
 
        self.assertEqual(parse("2003", default=self.default),
2833
 
                         datetime(2003, 9, 25))
2834
 
 
2835
 
    def testDateRCommandFormat(self):
2836
 
        self.assertEqual(parse("Thu, 25 Sep 2003 10:49:41 -0300"),
2837
 
                         datetime(2003, 9, 25, 10, 49, 41,
2838
 
                                  tzinfo=self.brsttz))
2839
 
 
2840
 
    def testISOFormat(self):
2841
 
        self.assertEqual(parse("2003-09-25T10:49:41.5-03:00"),
2842
 
                         datetime(2003, 9, 25, 10, 49, 41, 500000,
2843
 
                                  tzinfo=self.brsttz))
2844
 
 
2845
 
    def testISOFormatStrip1(self):
2846
 
        self.assertEqual(parse("2003-09-25T10:49:41-03:00"),
2847
 
                         datetime(2003, 9, 25, 10, 49, 41,
2848
 
                                  tzinfo=self.brsttz))
2849
 
 
2850
 
    def testISOFormatStrip2(self):
2851
 
        self.assertEqual(parse("2003-09-25T10:49:41"),
2852
 
                         datetime(2003, 9, 25, 10, 49, 41))
2853
 
 
2854
 
    def testISOFormatStrip3(self):
2855
 
        self.assertEqual(parse("2003-09-25T10:49"),
2856
 
                         datetime(2003, 9, 25, 10, 49))
2857
 
 
2858
 
    def testISOFormatStrip4(self):
2859
 
        self.assertEqual(parse("2003-09-25T10"),
2860
 
                         datetime(2003, 9, 25, 10))
2861
 
 
2862
 
    def testISOFormatStrip5(self):
2863
 
        self.assertEqual(parse("2003-09-25"),
2864
 
                         datetime(2003, 9, 25))
2865
 
 
2866
 
    def testISOStrippedFormat(self):
2867
 
        self.assertEqual(parse("20030925T104941.5-0300"),
2868
 
                         datetime(2003, 9, 25, 10, 49, 41, 500000,
2869
 
                                  tzinfo=self.brsttz))
2870
 
 
2871
 
    def testISOStrippedFormatStrip1(self):
2872
 
        self.assertEqual(parse("20030925T104941-0300"),
2873
 
                         datetime(2003, 9, 25, 10, 49, 41,
2874
 
                                  tzinfo=self.brsttz))
2875
 
 
2876
 
    def testISOStrippedFormatStrip2(self):
2877
 
        self.assertEqual(parse("20030925T104941"),
2878
 
                         datetime(2003, 9, 25, 10, 49, 41))
2879
 
 
2880
 
    def testISOStrippedFormatStrip3(self):
2881
 
        self.assertEqual(parse("20030925T1049"),
2882
 
                         datetime(2003, 9, 25, 10, 49, 0))
2883
 
 
2884
 
    def testISOStrippedFormatStrip4(self):
2885
 
        self.assertEqual(parse("20030925T10"),
2886
 
                         datetime(2003, 9, 25, 10))
2887
 
 
2888
 
    def testISOStrippedFormatStrip5(self):
2889
 
        self.assertEqual(parse("20030925"),
2890
 
                         datetime(2003, 9, 25))
2891
 
 
2892
 
    def testNoSeparator1(self):
2893
 
        self.assertEqual(parse("199709020908"),
2894
 
                         datetime(1997, 9, 2, 9, 8))
2895
 
 
2896
 
    def testNoSeparator2(self):
2897
 
        self.assertEqual(parse("19970902090807"),
2898
 
                         datetime(1997, 9, 2, 9, 8, 7))
2899
 
 
2900
 
    def testDateWithDash1(self):
2901
 
        self.assertEqual(parse("2003-09-25"),
2902
 
                         datetime(2003, 9, 25))
2903
 
 
2904
 
    def testDateWithDash2(self):
2905
 
        self.assertEqual(parse("2003-Sep-25"),
2906
 
                         datetime(2003, 9, 25))
2907
 
 
2908
 
    def testDateWithDash3(self):
2909
 
        self.assertEqual(parse("25-Sep-2003"),
2910
 
                         datetime(2003, 9, 25))
2911
 
 
2912
 
    def testDateWithDash4(self):
2913
 
        self.assertEqual(parse("25-Sep-2003"),
2914
 
                         datetime(2003, 9, 25))
2915
 
 
2916
 
    def testDateWithDash5(self):
2917
 
        self.assertEqual(parse("Sep-25-2003"),
2918
 
                         datetime(2003, 9, 25))
2919
 
 
2920
 
    def testDateWithDash6(self):
2921
 
        self.assertEqual(parse("09-25-2003"),
2922
 
                         datetime(2003, 9, 25))
2923
 
 
2924
 
    def testDateWithDash7(self):
2925
 
        self.assertEqual(parse("25-09-2003"),
2926
 
                         datetime(2003, 9, 25))
2927
 
 
2928
 
    def testDateWithDash8(self):
2929
 
        self.assertEqual(parse("10-09-2003", dayfirst=True),
2930
 
                         datetime(2003, 9, 10))
2931
 
 
2932
 
    def testDateWithDash9(self):
2933
 
        self.assertEqual(parse("10-09-2003"),
2934
 
                         datetime(2003, 10, 9))
2935
 
 
2936
 
    def testDateWithDash10(self):
2937
 
        self.assertEqual(parse("10-09-03"),
2938
 
                         datetime(2003, 10, 9))
2939
 
 
2940
 
    def testDateWithDash11(self):
2941
 
        self.assertEqual(parse("10-09-03", yearfirst=True),
2942
 
                         datetime(2010, 9, 3))
2943
 
 
2944
 
    def testDateWithDot1(self):
2945
 
        self.assertEqual(parse("2003.09.25"),
2946
 
                         datetime(2003, 9, 25))
2947
 
 
2948
 
    def testDateWithDot2(self):
2949
 
        self.assertEqual(parse("2003.Sep.25"),
2950
 
                         datetime(2003, 9, 25))
2951
 
 
2952
 
    def testDateWithDot3(self):
2953
 
        self.assertEqual(parse("25.Sep.2003"),
2954
 
                         datetime(2003, 9, 25))
2955
 
 
2956
 
    def testDateWithDot4(self):
2957
 
        self.assertEqual(parse("25.Sep.2003"),
2958
 
                         datetime(2003, 9, 25))
2959
 
 
2960
 
    def testDateWithDot5(self):
2961
 
        self.assertEqual(parse("Sep.25.2003"),
2962
 
                         datetime(2003, 9, 25))
2963
 
 
2964
 
    def testDateWithDot6(self):
2965
 
        self.assertEqual(parse("09.25.2003"),
2966
 
                         datetime(2003, 9, 25))
2967
 
 
2968
 
    def testDateWithDot7(self):
2969
 
        self.assertEqual(parse("25.09.2003"),
2970
 
                         datetime(2003, 9, 25))
2971
 
 
2972
 
    def testDateWithDot8(self):
2973
 
        self.assertEqual(parse("10.09.2003", dayfirst=True),
2974
 
                         datetime(2003, 9, 10))
2975
 
 
2976
 
    def testDateWithDot9(self):
2977
 
        self.assertEqual(parse("10.09.2003"),
2978
 
                         datetime(2003, 10, 9))
2979
 
 
2980
 
    def testDateWithDot10(self):
2981
 
        self.assertEqual(parse("10.09.03"),
2982
 
                         datetime(2003, 10, 9))
2983
 
 
2984
 
    def testDateWithDot11(self):
2985
 
        self.assertEqual(parse("10.09.03", yearfirst=True),
2986
 
                         datetime(2010, 9, 3))
2987
 
 
2988
 
    def testDateWithSlash1(self):
2989
 
        self.assertEqual(parse("2003/09/25"),
2990
 
                         datetime(2003, 9, 25))
2991
 
 
2992
 
    def testDateWithSlash2(self):
2993
 
        self.assertEqual(parse("2003/Sep/25"),
2994
 
                         datetime(2003, 9, 25))
2995
 
 
2996
 
    def testDateWithSlash3(self):
2997
 
        self.assertEqual(parse("25/Sep/2003"),
2998
 
                         datetime(2003, 9, 25))
2999
 
 
3000
 
    def testDateWithSlash4(self):
3001
 
        self.assertEqual(parse("25/Sep/2003"),
3002
 
                         datetime(2003, 9, 25))
3003
 
 
3004
 
    def testDateWithSlash5(self):
3005
 
        self.assertEqual(parse("Sep/25/2003"),
3006
 
                         datetime(2003, 9, 25))
3007
 
 
3008
 
    def testDateWithSlash6(self):
3009
 
        self.assertEqual(parse("09/25/2003"),
3010
 
                         datetime(2003, 9, 25))
3011
 
 
3012
 
    def testDateWithSlash7(self):
3013
 
        self.assertEqual(parse("25/09/2003"),
3014
 
                         datetime(2003, 9, 25))
3015
 
 
3016
 
    def testDateWithSlash8(self):
3017
 
        self.assertEqual(parse("10/09/2003", dayfirst=True),
3018
 
                         datetime(2003, 9, 10))
3019
 
 
3020
 
    def testDateWithSlash9(self):
3021
 
        self.assertEqual(parse("10/09/2003"),
3022
 
                         datetime(2003, 10, 9))
3023
 
 
3024
 
    def testDateWithSlash10(self):
3025
 
        self.assertEqual(parse("10/09/03"),
3026
 
                         datetime(2003, 10, 9))
3027
 
 
3028
 
    def testDateWithSlash11(self):
3029
 
        self.assertEqual(parse("10/09/03", yearfirst=True),
3030
 
                         datetime(2010, 9, 3))
3031
 
 
3032
 
    def testDateWithSpace12(self):
3033
 
        self.assertEqual(parse("25 09 03"),
3034
 
                         datetime(2003, 9, 25))
3035
 
 
3036
 
    def testDateWithSpace13(self):
3037
 
        self.assertEqual(parse("25 09 03"),
3038
 
                         datetime(2003, 9, 25))
3039
 
 
3040
 
    def testDateWithSpace1(self):
3041
 
        self.assertEqual(parse("2003 09 25"),
3042
 
                         datetime(2003, 9, 25))
3043
 
 
3044
 
    def testDateWithSpace2(self):
3045
 
        self.assertEqual(parse("2003 Sep 25"),
3046
 
                         datetime(2003, 9, 25))
3047
 
 
3048
 
    def testDateWithSpace3(self):
3049
 
        self.assertEqual(parse("25 Sep 2003"),
3050
 
                         datetime(2003, 9, 25))
3051
 
 
3052
 
    def testDateWithSpace4(self):
3053
 
        self.assertEqual(parse("25 Sep 2003"),
3054
 
                         datetime(2003, 9, 25))
3055
 
 
3056
 
    def testDateWithSpace5(self):
3057
 
        self.assertEqual(parse("Sep 25 2003"),
3058
 
                         datetime(2003, 9, 25))
3059
 
 
3060
 
    def testDateWithSpace6(self):
3061
 
        self.assertEqual(parse("09 25 2003"),
3062
 
                         datetime(2003, 9, 25))
3063
 
 
3064
 
    def testDateWithSpace7(self):
3065
 
        self.assertEqual(parse("25 09 2003"),
3066
 
                         datetime(2003, 9, 25))
3067
 
 
3068
 
    def testDateWithSpace8(self):
3069
 
        self.assertEqual(parse("10 09 2003", dayfirst=True),
3070
 
                         datetime(2003, 9, 10))
3071
 
 
3072
 
    def testDateWithSpace9(self):
3073
 
        self.assertEqual(parse("10 09 2003"),
3074
 
                         datetime(2003, 10, 9))
3075
 
 
3076
 
    def testDateWithSpace10(self):
3077
 
        self.assertEqual(parse("10 09 03"),
3078
 
                         datetime(2003, 10, 9))
3079
 
 
3080
 
    def testDateWithSpace11(self):
3081
 
        self.assertEqual(parse("10 09 03", yearfirst=True),
3082
 
                         datetime(2010, 9, 3))
3083
 
 
3084
 
    def testDateWithSpace12(self):
3085
 
        self.assertEqual(parse("25 09 03"),
3086
 
                         datetime(2003, 9, 25))
3087
 
 
3088
 
    def testDateWithSpace13(self):
3089
 
        self.assertEqual(parse("25 09 03"),
3090
 
                         datetime(2003, 9, 25))
3091
 
 
3092
 
    def testStrangelyOrderedDate1(self):
3093
 
        self.assertEqual(parse("03 25 Sep"),
3094
 
                         datetime(2003, 9, 25))
3095
 
 
3096
 
    def testStrangelyOrderedDate2(self):
3097
 
        self.assertEqual(parse("2003 25 Sep"),
3098
 
                         datetime(2003, 9, 25))
3099
 
 
3100
 
    def testStrangelyOrderedDate3(self):
3101
 
        self.assertEqual(parse("25 03 Sep"),
3102
 
                         datetime(2025, 9, 3))
3103
 
 
3104
 
    def testHourWithLetters(self):
3105
 
        self.assertEqual(parse("10h36m28.5s", default=self.default),
3106
 
                         datetime(2003, 9, 25, 10, 36, 28, 500000))
3107
 
 
3108
 
    def testHourWithLettersStrip1(self):
3109
 
        self.assertEqual(parse("10h36m28s", default=self.default),
3110
 
                         datetime(2003, 9, 25, 10, 36, 28))
3111
 
 
3112
 
    def testHourWithLettersStrip1(self):
3113
 
        self.assertEqual(parse("10h36m", default=self.default),
3114
 
                         datetime(2003, 9, 25, 10, 36))
3115
 
 
3116
 
    def testHourWithLettersStrip2(self):
3117
 
        self.assertEqual(parse("10h", default=self.default),
3118
 
                         datetime(2003, 9, 25, 10))
3119
 
 
3120
 
    def testHourAmPm1(self):
3121
 
        self.assertEqual(parse("10h am", default=self.default),
3122
 
                         datetime(2003, 9, 25, 10))
3123
 
 
3124
 
    def testHourAmPm2(self):
3125
 
        self.assertEqual(parse("10h pm", default=self.default),
3126
 
                         datetime(2003, 9, 25, 22))
3127
 
 
3128
 
    def testHourAmPm3(self):
3129
 
        self.assertEqual(parse("10am", default=self.default),
3130
 
                         datetime(2003, 9, 25, 10))
3131
 
 
3132
 
    def testHourAmPm4(self):
3133
 
        self.assertEqual(parse("10pm", default=self.default),
3134
 
                         datetime(2003, 9, 25, 22))
3135
 
 
3136
 
    def testHourAmPm5(self):
3137
 
        self.assertEqual(parse("10:00 am", default=self.default),
3138
 
                         datetime(2003, 9, 25, 10))
3139
 
 
3140
 
    def testHourAmPm6(self):
3141
 
        self.assertEqual(parse("10:00 pm", default=self.default),
3142
 
                         datetime(2003, 9, 25, 22))
3143
 
 
3144
 
    def testHourAmPm7(self):
3145
 
        self.assertEqual(parse("10:00am", default=self.default),
3146
 
                         datetime(2003, 9, 25, 10))
3147
 
 
3148
 
    def testHourAmPm8(self):
3149
 
        self.assertEqual(parse("10:00pm", default=self.default),
3150
 
                         datetime(2003, 9, 25, 22))
3151
 
 
3152
 
    def testHourAmPm9(self):
3153
 
        self.assertEqual(parse("10:00a.m", default=self.default),
3154
 
                         datetime(2003, 9, 25, 10))
3155
 
 
3156
 
    def testHourAmPm10(self):
3157
 
        self.assertEqual(parse("10:00p.m", default=self.default),
3158
 
                         datetime(2003, 9, 25, 22))
3159
 
 
3160
 
    def testHourAmPm11(self):
3161
 
        self.assertEqual(parse("10:00a.m.", default=self.default),
3162
 
                         datetime(2003, 9, 25, 10))
3163
 
 
3164
 
    def testHourAmPm12(self):
3165
 
        self.assertEqual(parse("10:00p.m.", default=self.default),
3166
 
                         datetime(2003, 9, 25, 22))
3167
 
 
3168
 
    def testPertain(self):
3169
 
        self.assertEqual(parse("Sep 03", default=self.default),
3170
 
                         datetime(2003, 9, 3))
3171
 
        self.assertEqual(parse("Sep of 03", default=self.default),
3172
 
                         datetime(2003, 9, 25))
3173
 
 
3174
 
    def testWeekdayAlone(self):
3175
 
        self.assertEqual(parse("Wed", default=self.default),
3176
 
                         datetime(2003, 10, 1))
3177
 
 
3178
 
    def testLongWeekday(self):
3179
 
        self.assertEqual(parse("Wednesday", default=self.default),
3180
 
                         datetime(2003, 10, 1))
3181
 
 
3182
 
    def testLongMonth(self):
3183
 
        self.assertEqual(parse("October", default=self.default),
3184
 
                         datetime(2003, 10, 25))
3185
 
 
3186
 
    def testFuzzy(self):
3187
 
        s = "Today is 25 of September of 2003, exactly " \
3188
 
            "at 10:49:41 with timezone -03:00."
3189
 
        self.assertEqual(parse(s, fuzzy=True),
3190
 
                         datetime(2003, 9, 25, 10, 49, 41,
3191
 
                                  tzinfo=self.brsttz))
3192
 
 
3193
 
    def testExtraSpace(self):
3194
 
        self.assertEqual(parse("  July   4 ,  1976   12:01:02   am  "),
3195
 
                         datetime(1976, 7, 4, 0, 1, 2))
3196
 
 
3197
 
    def testRandomFormat1(self):
3198
 
        self.assertEqual(parse("Wed, July 10, '96"),
3199
 
                         datetime(1996, 7, 10, 0, 0))
3200
 
 
3201
 
    def testRandomFormat2(self):
3202
 
        self.assertEqual(parse("1996.07.10 AD at 15:08:56 PDT",
3203
 
                               ignoretz=True),
3204
 
                         datetime(1996, 7, 10, 15, 8, 56))
3205
 
 
3206
 
    def testRandomFormat3(self):
3207
 
        self.assertEqual(parse("1996.July.10 AD 12:08 PM"),
3208
 
                         datetime(1996, 7, 10, 12, 8))
3209
 
 
3210
 
    def testRandomFormat4(self):
3211
 
        self.assertEqual(parse("Tuesday, April 12, 1952 AD 3:30:42pm PST",
3212
 
                               ignoretz=True),
3213
 
                         datetime(1952, 4, 12, 15, 30, 42))
3214
 
 
3215
 
    def testRandomFormat5(self):
3216
 
        self.assertEqual(parse("November 5, 1994, 8:15:30 am EST",
3217
 
                               ignoretz=True),
3218
 
                         datetime(1994, 11, 5, 8, 15, 30))
3219
 
 
3220
 
    def testRandomFormat6(self):
3221
 
        self.assertEqual(parse("1994-11-05T08:15:30-05:00",
3222
 
                               ignoretz=True),
3223
 
                         datetime(1994, 11, 5, 8, 15, 30))
3224
 
 
3225
 
    def testRandomFormat7(self):
3226
 
        self.assertEqual(parse("1994-11-05T08:15:30Z",
3227
 
                               ignoretz=True),
3228
 
                         datetime(1994, 11, 5, 8, 15, 30))
3229
 
 
3230
 
    def testRandomFormat8(self):
3231
 
        self.assertEqual(parse("July 4, 1976"), datetime(1976, 7, 4))
3232
 
 
3233
 
    def testRandomFormat9(self):
3234
 
        self.assertEqual(parse("7 4 1976"), datetime(1976, 7, 4))
3235
 
 
3236
 
    def testRandomFormat10(self):
3237
 
        self.assertEqual(parse("4 jul 1976"), datetime(1976, 7, 4))
3238
 
 
3239
 
    def testRandomFormat11(self):
3240
 
        self.assertEqual(parse("7-4-76"), datetime(1976, 7, 4))
3241
 
 
3242
 
    def testRandomFormat12(self):
3243
 
        self.assertEqual(parse("19760704"), datetime(1976, 7, 4))
3244
 
 
3245
 
    def testRandomFormat13(self):
3246
 
        self.assertEqual(parse("0:01:02", default=self.default),
3247
 
                         datetime(2003, 9, 25, 0, 1, 2))
3248
 
 
3249
 
    def testRandomFormat14(self):
3250
 
        self.assertEqual(parse("12h 01m02s am", default=self.default),
3251
 
                         datetime(2003, 9, 25, 0, 1, 2))
3252
 
 
3253
 
    def testRandomFormat15(self):
3254
 
        self.assertEqual(parse("0:01:02 on July 4, 1976"),
3255
 
                         datetime(1976, 7, 4, 0, 1, 2))
3256
 
 
3257
 
    def testRandomFormat16(self):
3258
 
        self.assertEqual(parse("0:01:02 on July 4, 1976"),
3259
 
                         datetime(1976, 7, 4, 0, 1, 2))
3260
 
 
3261
 
    def testRandomFormat17(self):
3262
 
        self.assertEqual(parse("1976-07-04T00:01:02Z", ignoretz=True),
3263
 
                         datetime(1976, 7, 4, 0, 1, 2))
3264
 
 
3265
 
    def testRandomFormat18(self):
3266
 
        self.assertEqual(parse("July 4, 1976 12:01:02 am"),
3267
 
                         datetime(1976, 7, 4, 0, 1, 2))
3268
 
 
3269
 
    def testRandomFormat19(self):
3270
 
        self.assertEqual(parse("Mon Jan  2 04:24:27 1995"),
3271
 
                         datetime(1995, 1, 2, 4, 24, 27))
3272
 
 
3273
 
    def testRandomFormat20(self):
3274
 
        self.assertEqual(parse("Tue Apr 4 00:22:12 PDT 1995", ignoretz=True),
3275
 
                         datetime(1995, 4, 4, 0, 22, 12))
3276
 
 
3277
 
    def testRandomFormat21(self):
3278
 
        self.assertEqual(parse("04.04.95 00:22"),
3279
 
                         datetime(1995, 4, 4, 0, 22))
3280
 
 
3281
 
    def testRandomFormat22(self):
3282
 
        self.assertEqual(parse("Jan 1 1999 11:23:34.578"),
3283
 
                         datetime(1999, 1, 1, 11, 23, 34, 578000))
3284
 
 
3285
 
    def testRandomFormat23(self):
3286
 
        self.assertEqual(parse("950404 122212"),
3287
 
                         datetime(1995, 4, 4, 12, 22, 12))
3288
 
 
3289
 
    def testRandomFormat24(self):
3290
 
        self.assertEqual(parse("0:00 PM, PST", default=self.default,
3291
 
                               ignoretz=True),
3292
 
                         datetime(2003, 9, 25, 12, 0))
3293
 
 
3294
 
    def testRandomFormat25(self):
3295
 
        self.assertEqual(parse("12:08 PM", default=self.default),
3296
 
                         datetime(2003, 9, 25, 12, 8))
3297
 
 
3298
 
    def testRandomFormat26(self):
3299
 
        self.assertEqual(parse("5:50 A.M. on June 13, 1990"),
3300
 
                         datetime(1990, 6, 13, 5, 50))
3301
 
 
3302
 
    def testRandomFormat27(self):
3303
 
        self.assertEqual(parse("3rd of May 2001"), datetime(2001, 5, 3))
3304
 
 
3305
 
    def testRandomFormat28(self):
3306
 
        self.assertEqual(parse("5th of March 2001"), datetime(2001, 3, 5))
3307
 
 
3308
 
    def testRandomFormat29(self):
3309
 
        self.assertEqual(parse("1st of May 2003"), datetime(2003, 5, 1))
3310
 
 
3311
 
    def testRandomFormat30(self):
3312
 
        self.assertEqual(parse("01h02m03", default=self.default),
3313
 
                         datetime(2003, 9, 25, 1, 2, 3))
3314
 
 
3315
 
    def testRandomFormat31(self):
3316
 
        self.assertEqual(parse("01h02", default=self.default),
3317
 
                         datetime(2003, 9, 25, 1, 2))
3318
 
 
3319
 
    def testRandomFormat32(self):
3320
 
        self.assertEqual(parse("01h02s", default=self.default),
3321
 
                         datetime(2003, 9, 25, 1, 0, 2))
3322
 
 
3323
 
    def testRandomFormat33(self):
3324
 
        self.assertEqual(parse("01m02", default=self.default),
3325
 
                         datetime(2003, 9, 25, 0, 1, 2))
3326
 
 
3327
 
    def testRandomFormat34(self):
3328
 
        self.assertEqual(parse("01m02h", default=self.default),
3329
 
                         datetime(2003, 9, 25, 2, 1))
3330
 
 
3331
 
    def testIncreasingCTime(self):
3332
 
        # This test will check 200 different years, every month, every day,
3333
 
        # every hour, every minute, severy second, and every weekday, using
3334
 
        # a delta of more or less 1 year, 1 month, 1 day, 1 minute and
3335
 
        # 1 second.
3336
 
        delta = timedelta(days=365+31+1, seconds=1+60+60*60)
3337
 
        dt = datetime(1900, 1, 1, 0, 0, 0, 0)
3338
 
        for i in range(200):
3339
 
            self.assertEqual(parse(dt.ctime()), dt)
3340
 
            dt += delta
3341
 
 
3342
 
    def testIncreasingISOFormat(self):
3343
 
        delta = timedelta(days=365+31+1, seconds=1+60+60*60)
3344
 
        dt = datetime(1900, 1, 1, 0, 0, 0, 0)
3345
 
        for i in range(200):
3346
 
            self.assertEqual(parse(dt.isoformat()), dt)
3347
 
            dt += delta
3348
 
 
3349
 
class EasterTest(unittest.TestCase):
3350
 
    easterlist = [
3351
 
                 # WESTERN            ORTHODOX
3352
 
                  (date(1990, 4, 15), date(1990, 4, 15)),
3353
 
                  (date(1991, 3, 31), date(1991, 4,  7)),
3354
 
                  (date(1992, 4, 19), date(1992, 4, 26)),
3355
 
                  (date(1993, 4, 11), date(1993, 4, 18)),
3356
 
                  (date(1994, 4,  3), date(1994, 5,  1)),
3357
 
                  (date(1995, 4, 16), date(1995, 4, 23)),
3358
 
                  (date(1996, 4,  7), date(1996, 4, 14)),
3359
 
                  (date(1997, 3, 30), date(1997, 4, 27)),
3360
 
                  (date(1998, 4, 12), date(1998, 4, 19)),
3361
 
                  (date(1999, 4,  4), date(1999, 4, 11)),
3362
 
 
3363
 
                  (date(2000, 4, 23), date(2000, 4, 30)),
3364
 
                  (date(2001, 4, 15), date(2001, 4, 15)),
3365
 
                  (date(2002, 3, 31), date(2002, 5,  5)),
3366
 
                  (date(2003, 4, 20), date(2003, 4, 27)),
3367
 
                  (date(2004, 4, 11), date(2004, 4, 11)),
3368
 
                  (date(2005, 3, 27), date(2005, 5,  1)),
3369
 
                  (date(2006, 4, 16), date(2006, 4, 23)),
3370
 
                  (date(2007, 4,  8), date(2007, 4,  8)),
3371
 
                  (date(2008, 3, 23), date(2008, 4, 27)),
3372
 
                  (date(2009, 4, 12), date(2009, 4, 19)),
3373
 
 
3374
 
                  (date(2010, 4,  4), date(2010, 4,  4)),
3375
 
                  (date(2011, 4, 24), date(2011, 4, 24)),
3376
 
                  (date(2012, 4,  8), date(2012, 4, 15)),
3377
 
                  (date(2013, 3, 31), date(2013, 5,  5)),
3378
 
                  (date(2014, 4, 20), date(2014, 4, 20)),
3379
 
                  (date(2015, 4,  5), date(2015, 4, 12)),
3380
 
                  (date(2016, 3, 27), date(2016, 5,  1)),
3381
 
                  (date(2017, 4, 16), date(2017, 4, 16)),
3382
 
                  (date(2018, 4,  1), date(2018, 4,  8)),
3383
 
                  (date(2019, 4, 21), date(2019, 4, 28)),
3384
 
 
3385
 
                  (date(2020, 4, 12), date(2020, 4, 19)),
3386
 
                  (date(2021, 4,  4), date(2021, 5,  2)),
3387
 
                  (date(2022, 4, 17), date(2022, 4, 24)),
3388
 
                  (date(2023, 4,  9), date(2023, 4, 16)),
3389
 
                  (date(2024, 3, 31), date(2024, 5,  5)),
3390
 
                  (date(2025, 4, 20), date(2025, 4, 20)),
3391
 
                  (date(2026, 4,  5), date(2026, 4, 12)),
3392
 
                  (date(2027, 3, 28), date(2027, 5,  2)),
3393
 
                  (date(2028, 4, 16), date(2028, 4, 16)),
3394
 
                  (date(2029, 4,  1), date(2029, 4,  8)),
3395
 
 
3396
 
                  (date(2030, 4, 21), date(2030, 4, 28)),
3397
 
                  (date(2031, 4, 13), date(2031, 4, 13)),
3398
 
                  (date(2032, 3, 28), date(2032, 5,  2)),
3399
 
                  (date(2033, 4, 17), date(2033, 4, 24)),
3400
 
                  (date(2034, 4,  9), date(2034, 4,  9)),
3401
 
                  (date(2035, 3, 25), date(2035, 4, 29)),
3402
 
                  (date(2036, 4, 13), date(2036, 4, 20)),
3403
 
                  (date(2037, 4,  5), date(2037, 4,  5)),
3404
 
                  (date(2038, 4, 25), date(2038, 4, 25)),
3405
 
                  (date(2039, 4, 10), date(2039, 4, 17)),
3406
 
 
3407
 
                  (date(2040, 4,  1), date(2040, 5,  6)),
3408
 
                  (date(2041, 4, 21), date(2041, 4, 21)),
3409
 
                  (date(2042, 4,  6), date(2042, 4, 13)),
3410
 
                  (date(2043, 3, 29), date(2043, 5,  3)),
3411
 
                  (date(2044, 4, 17), date(2044, 4, 24)),
3412
 
                  (date(2045, 4,  9), date(2045, 4,  9)),
3413
 
                  (date(2046, 3, 25), date(2046, 4, 29)),
3414
 
                  (date(2047, 4, 14), date(2047, 4, 21)),
3415
 
                  (date(2048, 4,  5), date(2048, 4,  5)),
3416
 
                  (date(2049, 4, 18), date(2049, 4, 25)),
3417
 
 
3418
 
                  (date(2050, 4, 10), date(2050, 4, 17)),
3419
 
                ]
3420
 
 
3421
 
    def testEaster(self):
3422
 
        for western, orthodox in self.easterlist:
3423
 
            self.assertEqual(western,  easter(western.year,  EASTER_WESTERN))
3424
 
            self.assertEqual(orthodox, easter(orthodox.year, EASTER_ORTHODOX))
3425
 
 
3426
 
class TZTest(unittest.TestCase):
3427
 
 
3428
 
    TZFILE_EST5EDT = """
3429
 
VFppZgAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAAAAADrAAAABAAAABCeph5wn7rrYKCGAHCh
3430
 
ms1gomXicKOD6eCkaq5wpTWnYKZTyvCnFYlgqDOs8Kj+peCqE47wqt6H4KvzcPCsvmngrdNS8K6e
3431
 
S+CvszTwsH4t4LGcUXCyZ0pgs3wzcLRHLGC1XBVwticOYLc793C4BvBguRvZcLnm0mC7BPXwu8a0
3432
 
YLzk1/C9r9DgvsS58L+PsuDApJvwwW+U4MKEffDDT3bgxGRf8MUvWODGTXxwxw864MgtXnDI+Fdg
3433
 
yg1AcMrYOWDLiPBw0iP0cNJg++DTdeTw1EDd4NVVxvDWIL/g1zWo8NgAoeDZFYrw2eCD4Nr+p3Db
3434
 
wGXg3N6JcN2pgmDevmtw34lkYOCeTXDhaUZg4n4vcONJKGDkXhFw5Vcu4OZHLfDnNxDg6CcP8OkW
3435
 
8uDqBvHw6vbU4Ovm0/Ds1rbg7ca18O6/02Dvr9Jw8J+1YPGPtHDyf5dg82+WcPRfeWD1T3hw9j9b
3436
 
YPcvWnD4KHfg+Q88cPoIWeD6+Fjw++g74PzYOvD9yB3g/rgc8P+n/+AAl/7wAYfh4AJ34PADcP5g
3437
 
BGD9cAVQ4GAGQN9wBzDCYAeNGXAJEKRgCa2U8ArwhmAL4IVwDNmi4A3AZ3AOuYTgD6mD8BCZZuAR
3438
 
iWXwEnlI4BNpR/AUWSrgFUkp8BY5DOAXKQvwGCIpYBkI7fAaAgtgGvIKcBvh7WAc0exwHcHPYB6x
3439
 
znAfobFgIHYA8CGBk2AiVeLwI2qv4CQ1xPAlSpHgJhWm8Ccqc+An/sNwKQpV4CnepXAq6jfgK76H
3440
 
cCzTVGAtnmlwLrM2YC9+S3AwkxhgMWdn8DJy+mAzR0nwNFLcYDUnK/A2Mr5gNwcN8Dgb2uA45u/w
3441
 
Ofu84DrG0fA7257gPK/ucD27gOA+j9BwP5ti4EBvsnBBhH9gQk+UcENkYWBEL3ZwRURDYEYPWHBH
3442
 
JCVgR/h08EkEB2BJ2FbwSuPpYEu4OPBMzQXgTZga8E6s5+BPd/zwUIzJ4FFhGXBSbKvgU0D7cFRM
3443
 
jeBVIN1wVixv4FcAv3BYFYxgWOChcFn1bmBawINwW9VQYFypn/BdtTJgXomB8F+VFGBgaWPwYX4w
3444
 
4GJJRfBjXhLgZCkn8GU99OBmEkRwZx3W4GfyJnBo/bjgadIIcGrdmuBrsepwbMa3YG2RzHBupplg
3445
 
b3GucHCGe2BxWsrwcmZdYHM6rPB0Rj9gdRqO8HYvW+B2+nDweA894HjaUvB57x/gero08HvPAeB8
3446
 
o1Fwfa7j4H6DM3B/jsXgAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAB
3447
 
AAEAAQABAgMBAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAB
3448
 
AAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEA
3449
 
AQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAB
3450
 
AAEAAQABAAEAAQABAAEAAQABAAEAAf//x8ABAP//ubAABP//x8ABCP//x8ABDEVEVABFU1QARVdU
3451
 
AEVQVAAAAAABAAAAAQ==
3452
 
    """
3453
 
 
3454
 
    TZICAL_EST5EDT = """
3455
 
BEGIN:VTIMEZONE
3456
 
TZID:US-Eastern
3457
 
LAST-MODIFIED:19870101T000000Z
3458
 
TZURL:http://zones.stds_r_us.net/tz/US-Eastern
3459
 
BEGIN:STANDARD
3460
 
DTSTART:19671029T020000
3461
 
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
3462
 
TZOFFSETFROM:-0400
3463
 
TZOFFSETTO:-0500
3464
 
TZNAME:EST
3465
 
END:STANDARD
3466
 
BEGIN:DAYLIGHT
3467
 
DTSTART:19870405T020000
3468
 
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
3469
 
TZOFFSETFROM:-0500
3470
 
TZOFFSETTO:-0400
3471
 
TZNAME:EDT
3472
 
END:DAYLIGHT
3473
 
END:VTIMEZONE
3474
 
    """
3475
 
 
3476
 
    def testStrStart1(self):
3477
 
        self.assertEqual(datetime(2003,4,6,1,59,
3478
 
                                  tzinfo=tzstr("EST5EDT")).tzname(), "EST")
3479
 
        self.assertEqual(datetime(2003,4,6,2,00,
3480
 
                                  tzinfo=tzstr("EST5EDT")).tzname(), "EDT")
3481
 
 
3482
 
    def testStrEnd1(self):
3483
 
        self.assertEqual(datetime(2003,10,26,0,59,
3484
 
                                  tzinfo=tzstr("EST5EDT")).tzname(), "EDT")
3485
 
        self.assertEqual(datetime(2003,10,26,1,00,
3486
 
                                  tzinfo=tzstr("EST5EDT")).tzname(), "EST")
3487
 
 
3488
 
    def testStrStart2(self):
3489
 
        s = "EST5EDT,4,0,6,7200,10,0,26,7200,3600"
3490
 
        self.assertEqual(datetime(2003,4,6,1,59,
3491
 
                                  tzinfo=tzstr(s)).tzname(), "EST")
3492
 
        self.assertEqual(datetime(2003,4,6,2,00,
3493
 
                                  tzinfo=tzstr(s)).tzname(), "EDT")
3494
 
 
3495
 
    def testStrEnd2(self):
3496
 
        s = "EST5EDT,4,0,6,7200,10,0,26,7200,3600"
3497
 
        self.assertEqual(datetime(2003,10,26,0,59,
3498
 
                                  tzinfo=tzstr(s)).tzname(), "EDT")
3499
 
        self.assertEqual(datetime(2003,10,26,1,00,
3500
 
                                  tzinfo=tzstr(s)).tzname(), "EST")
3501
 
 
3502
 
    def testStrStart3(self):
3503
 
        s = "EST5EDT,4,1,0,7200,10,-1,0,7200,3600"
3504
 
        self.assertEqual(datetime(2003,4,6,1,59,
3505
 
                                  tzinfo=tzstr(s)).tzname(), "EST")
3506
 
        self.assertEqual(datetime(2003,4,6,2,00,
3507
 
                                  tzinfo=tzstr(s)).tzname(), "EDT")
3508
 
 
3509
 
    def testStrEnd3(self):
3510
 
        s = "EST5EDT,4,1,0,7200,10,-1,0,7200,3600"
3511
 
        self.assertEqual(datetime(2003,10,26,0,59,
3512
 
                                  tzinfo=tzstr(s)).tzname(), "EDT")
3513
 
        self.assertEqual(datetime(2003,10,26,1,00,
3514
 
                                  tzinfo=tzstr(s)).tzname(), "EST")
3515
 
 
3516
 
    def testStrStart4(self):
3517
 
        s = "EST5EDT4,M4.1.0/02:00:00,M10-5-0/02:00"
3518
 
        self.assertEqual(datetime(2003,4,6,1,59,
3519
 
                                  tzinfo=tzstr(s)).tzname(), "EST")
3520
 
        self.assertEqual(datetime(2003,4,6,2,00,
3521
 
                                  tzinfo=tzstr(s)).tzname(), "EDT")
3522
 
 
3523
 
    def testStrEnd4(self):
3524
 
        s = "EST5EDT4,M4.1.0/02:00:00,M10-5-0/02:00"
3525
 
        self.assertEqual(datetime(2003,10,26,0,59,
3526
 
                                  tzinfo=tzstr(s)).tzname(), "EDT")
3527
 
        self.assertEqual(datetime(2003,10,26,1,00,
3528
 
                                  tzinfo=tzstr(s)).tzname(), "EST")
3529
 
 
3530
 
    def testStrStart5(self):
3531
 
        s = "EST5EDT4,95/02:00:00,298/02:00"
3532
 
        self.assertEqual(datetime(2003,4,6,1,59,
3533
 
                                  tzinfo=tzstr(s)).tzname(), "EST")
3534
 
        self.assertEqual(datetime(2003,4,6,2,00,
3535
 
                                  tzinfo=tzstr(s)).tzname(), "EDT")
3536
 
 
3537
 
    def testStrEnd5(self):
3538
 
        s = "EST5EDT4,95/02:00:00,298/02"
3539
 
        self.assertEqual(datetime(2003,10,26,0,59,
3540
 
                                  tzinfo=tzstr(s)).tzname(), "EDT")
3541
 
        self.assertEqual(datetime(2003,10,26,1,00,
3542
 
                                  tzinfo=tzstr(s)).tzname(), "EST")
3543
 
 
3544
 
    def testStrStart6(self):
3545
 
        s = "EST5EDT4,J96/02:00:00,J299/02:00"
3546
 
        self.assertEqual(datetime(2003,4,6,1,59,
3547
 
                                  tzinfo=tzstr(s)).tzname(), "EST")
3548
 
        self.assertEqual(datetime(2003,4,6,2,00,
3549
 
                                  tzinfo=tzstr(s)).tzname(), "EDT")
3550
 
 
3551
 
    def testStrEnd6(self):
3552
 
        s = "EST5EDT4,J96/02:00:00,J299/02"
3553
 
        self.assertEqual(datetime(2003,10,26,0,59,
3554
 
                                  tzinfo=tzstr(s)).tzname(), "EDT")
3555
 
        self.assertEqual(datetime(2003,10,26,1,00,
3556
 
                                  tzinfo=tzstr(s)).tzname(), "EST")
3557
 
 
3558
 
    def testStrCmp1(self):
3559
 
        self.assertEqual(tzstr("EST5EDT"),
3560
 
                         tzstr("EST5EDT4,M4.1.0/02:00:00,M10-5-0/02:00"))
3561
 
        
3562
 
    def testStrCmp2(self):
3563
 
        self.assertEqual(tzstr("EST5EDT"),
3564
 
                         tzstr("EST5EDT,4,1,0,7200,10,-1,0,7200,3600"))
3565
 
 
3566
 
    def testRangeCmp1(self):
3567
 
        self.assertEqual(tzstr("EST5EDT"),
3568
 
                         tzrange("EST", -18000, "EDT", -14400,
3569
 
                                 relativedelta(hours=+2,
3570
 
                                               month=4, day=1,
3571
 
                                               weekday=SU(+1)),
3572
 
                                 relativedelta(hours=+1,
3573
 
                                               month=10, day=31,
3574
 
                                               weekday=SU(-1))))
3575
 
 
3576
 
    def testRangeCmp2(self):
3577
 
        self.assertEqual(tzstr("EST5EDT"),
3578
 
                         tzrange("EST", -18000, "EDT"))
3579
 
 
3580
 
    def testFileStart1(self):
3581
 
        tz = tzfile(StringIO(base64.decodestring(self.TZFILE_EST5EDT)))
3582
 
        self.assertEqual(datetime(2003,4,6,1,59,tzinfo=tz).tzname(), "EST")
3583
 
        self.assertEqual(datetime(2003,4,6,2,00,tzinfo=tz).tzname(), "EDT")
3584
 
        
3585
 
    def testFileEnd1(self):
3586
 
        tz = tzfile(StringIO(base64.decodestring(self.TZFILE_EST5EDT)))
3587
 
        self.assertEqual(datetime(2003,10,26,0,59,tzinfo=tz).tzname(), "EDT")
3588
 
        self.assertEqual(datetime(2003,10,26,1,00,tzinfo=tz).tzname(), "EST")
3589
 
 
3590
 
    def testICalStart1(self):
3591
 
        tz = tzical(StringIO(self.TZICAL_EST5EDT)).get()
3592
 
        self.assertEqual(datetime(2003,4,6,1,59,tzinfo=tz).tzname(), "EST")
3593
 
        self.assertEqual(datetime(2003,4,6,2,00,tzinfo=tz).tzname(), "EDT")
3594
 
 
3595
 
    def testICalEnd1(self):
3596
 
        tz = tzical(StringIO(self.TZICAL_EST5EDT)).get()
3597
 
        self.assertEqual(datetime(2003,10,26,0,59,tzinfo=tz).tzname(), "EDT")
3598
 
        self.assertEqual(datetime(2003,10,26,1,00,tzinfo=tz).tzname(), "EST")
3599
 
 
3600
 
if __name__ == "__main__":
3601
 
        unittest.main()
3602
 
 
3603
 
# vim:ts=4:sw=4