3
from cStringIO import StringIO
7
# Add build directory to search path
8
if os.path.exists("build"):
9
from distutils.util import get_platform
11
s = "build/lib.%s-%.3s" % (get_platform(), sys.version)
12
s = os.path.join(os.getcwd(), s)
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 *
21
from datetime import *
26
class RelativeDeltaTest(unittest.TestCase):
27
now = datetime(2003, 9, 17, 20, 54, 47, 282310)
28
today = date(2003, 9, 17)
30
def testNextMonth(self):
31
self.assertEqual(self.now+relativedelta(months=+1),
32
datetime(2003, 10, 17, 20, 54, 47, 282310))
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))
42
def testNextMonthPlusOneWeek10amDiff(self):
43
self.assertEqual(relativedelta(datetime(2003, 10, 24, 10, 0),
45
relativedelta(months=+1, days=+7, hours=+10))
47
def testOneMonthBeforeOneYear(self):
48
self.assertEqual(self.now+relativedelta(years=+1, months=-1),
49
datetime(2004, 8, 17, 20, 54, 47, 282310))
51
def testMonthsOfDiffNumOfDays(self):
52
self.assertEqual(date(2003, 1, 27)+relativedelta(months=+1),
54
self.assertEqual(date(2003, 1, 31)+relativedelta(months=+1),
56
self.assertEqual(date(2003, 1, 31)+relativedelta(months=+2),
59
def testMonthsOfDiffNumOfDaysWithYears(self):
60
self.assertEqual(date(2000, 2, 28)+relativedelta(years=+1),
62
self.assertEqual(date(2000, 2, 29)+relativedelta(years=+1),
65
self.assertEqual(date(1999, 2, 28)+relativedelta(years=+1),
67
self.assertEqual(date(1999, 3, 1)+relativedelta(years=+1),
69
self.assertEqual(date(1999, 3, 1)+relativedelta(years=+1),
72
self.assertEqual(date(2001, 2, 28)+relativedelta(years=-1),
74
self.assertEqual(date(2001, 3, 1)+relativedelta(years=-1),
77
def testNextFriday(self):
78
self.assertEqual(self.today+relativedelta(weekday=FR),
81
def testNextFridayInt(self):
82
self.assertEqual(self.today+relativedelta(weekday=calendar.FRIDAY),
85
def testLastFridayInThisMonth(self):
86
self.assertEqual(self.today+relativedelta(day=31, weekday=FR(-1)),
89
def testNextWednesdayIsToday(self):
90
self.assertEqual(self.today+relativedelta(weekday=WE),
94
def testNextWenesdayNotToday(self):
95
self.assertEqual(self.today+relativedelta(days=+1, weekday=WE),
98
def test15thISOYearWeek(self):
99
self.assertEqual(date(2003, 1, 1) +
100
relativedelta(day=4, weeks=+14, weekday=MO(-1)),
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))
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))
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,
122
def testYearDay(self):
123
self.assertEqual(date(2003, 1, 1)+relativedelta(yearday=260),
125
self.assertEqual(date(2002, 1, 1)+relativedelta(yearday=260),
127
self.assertEqual(date(2000, 1, 1)+relativedelta(yearday=260),
129
self.assertEqual(self.today+relativedelta(yearday=261),
132
def testNonLeapYearDay(self):
133
self.assertEqual(date(2003, 1, 1)+relativedelta(nlyearday=260),
135
self.assertEqual(date(2002, 1, 1)+relativedelta(nlyearday=260),
137
self.assertEqual(date(2000, 1, 1)+relativedelta(nlyearday=260),
139
self.assertEqual(self.today+relativedelta(yearday=261),
142
class RRuleTest(unittest.TestCase):
144
def testYearly(self):
145
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
152
def testYearlyInterval(self):
153
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
161
def testYearlyIntervalLarge(self):
162
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
170
def testYearlyByMonth(self):
171
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
179
def testYearlyByMonthDay(self):
180
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
188
def testYearlyByMonthAndMonthDay(self):
189
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
198
def testYearlyByWeekDay(self):
199
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
207
def testYearlyByNWeekDay(self):
208
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
216
def testYearlyByNWeekDayLarge(self):
217
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
225
def testYearlyByMonthAndWeekDay(self):
226
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
235
def testYearlyByMonthAndNWeekDay(self):
236
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
245
def testYearlyByMonthAndNWeekDayLarge(self):
246
# This is interesting because the TH(-3) ends up before
248
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
257
def testYearlyByMonthDayAndWeekDay(self):
258
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
267
def testYearlyByMonthAndMonthDayAndWeekDay(self):
268
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
278
def testYearlyByYearDay(self):
279
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
287
def testYearlyByMonthAndYearDay(self):
288
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
297
def testYearlyByWeekNo(self):
298
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
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,
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)])
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,
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)])
330
def testYearlyByWeekNoAndWeekDayLast(self):
331
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
340
def testYearlyByEaster(self):
341
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
349
def testYearlyByEasterPos(self):
350
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
358
def testYearlyByEasterNeg(self):
359
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
367
def testYearlyByWeekNoAndWeekDay53(self):
368
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
377
def testYearlyByWeekNoAndWeekDay53(self):
378
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
387
def testYearlyByHour(self):
388
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
396
def testYearlyByMinute(self):
397
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
405
def testYearlyBySecond(self):
406
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
414
def testYearlyByHourAndMinute(self):
415
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
424
def testYearlyByHourAndSecond(self):
425
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
434
def testYearlyByMinuteAndSecond(self):
435
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
444
def testYearlyByHourAndMinuteAndSecond(self):
445
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
455
def testYearlyBySetPos(self):
456
self.assertEqual(list(rrule(FREQ_YEARLY,
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)])
466
def testMonthly(self):
467
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
474
def testMonthlyInterval(self):
475
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
483
def testMonthlyIntervalLarge(self):
484
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
492
def testMonthlyByMonth(self):
493
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
502
def testMonthlyByMonthDay(self):
503
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
511
def testMonthlyByMonthAndMonthDay(self):
512
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
521
def testMonthlyByWeekDay(self):
522
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
530
def testMonthlyByNWeekDay(self):
531
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
539
def testMonthlyByNWeekDayLarge(self):
540
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
548
def testMonthlyByMonthAndWeekDay(self):
549
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
558
def testMonthlyByMonthAndNWeekDay(self):
559
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
568
def testMonthlyByMonthAndNWeekDayLarge(self):
569
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
578
def testMonthlyByMonthDayAndWeekDay(self):
579
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
588
def testMonthlyByMonthAndMonthDayAndWeekDay(self):
589
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
599
def testMonthlyByYearDay(self):
600
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
608
def testMonthlyByMonthAndYearDay(self):
609
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
618
def testMonthlyByWeekNo(self):
619
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
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,
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)])
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,
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)])
651
def testMonthlyByWeekNoAndWeekDayLast(self):
652
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
661
def testMonthlyByWeekNoAndWeekDay53(self):
662
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
671
def testMonthlyByEaster(self):
672
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
680
def testMonthlyByEasterPos(self):
681
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
689
def testMonthlyByEasterNeg(self):
690
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
698
def testMonthlyByHour(self):
699
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
707
def testMonthlyByMinute(self):
708
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
716
def testMonthlyBySecond(self):
717
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
725
def testMonthlyByHourAndMinute(self):
726
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
735
def testMonthlyByHourAndSecond(self):
736
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
745
def testMonthlyByMinuteAndSecond(self):
746
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
755
def testMonthlyByHourAndMinuteAndSecond(self):
756
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
766
def testMonthlyBySetPos(self):
767
self.assertEqual(list(rrule(FREQ_MONTHLY,
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)])
777
def testWeekly(self):
778
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
785
def testWeeklyInterval(self):
786
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
794
def testWeeklyIntervalLarge(self):
795
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
803
def testWeeklyByMonth(self):
804
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
812
def testWeeklyByMonthDay(self):
813
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
821
def testWeeklyByMonthAndMonthDay(self):
822
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
831
def testWeeklyByWeekDay(self):
832
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
840
def testWeeklyByNWeekDay(self):
841
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
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
853
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
862
def testWeeklyByMonthAndNWeekDay(self):
863
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
872
def testWeeklyByMonthDayAndWeekDay(self):
873
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
882
def testWeeklyByMonthAndMonthDayAndWeekDay(self):
883
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
893
def testWeeklyByYearDay(self):
894
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
902
def testWeeklyByMonthAndYearDay(self):
903
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
912
def testWeeklyByWeekNo(self):
913
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
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,
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)])
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,
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)])
945
def testWeeklyByWeekNoAndWeekDayLast(self):
946
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
955
def testWeeklyByWeekNoAndWeekDay53(self):
956
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
965
def testWeeklyByEaster(self):
966
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
974
def testWeeklyByEasterPos(self):
975
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
983
def testWeeklyByEasterNeg(self):
984
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
992
def testWeeklyByHour(self):
993
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
1001
def testWeeklyByMinute(self):
1002
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
1010
def testWeeklyBySecond(self):
1011
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
1019
def testWeeklyByHourAndMinute(self):
1020
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
1029
def testWeeklyByHourAndSecond(self):
1030
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
1039
def testWeeklyByMinuteAndSecond(self):
1040
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
1049
def testWeeklyByHourAndMinuteAndSecond(self):
1050
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
1060
def testWeeklyBySetPos(self):
1061
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
1071
def testDaily(self):
1072
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1079
def testDailyInterval(self):
1080
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1088
def testDailyIntervalLarge(self):
1089
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1097
def testDailyByMonth(self):
1098
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1106
def testDailyByMonthDay(self):
1107
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1115
def testDailyByMonthAndMonthDay(self):
1116
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1125
def testDailyByWeekDay(self):
1126
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1134
def testDailyByNWeekDay(self):
1135
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1143
def testDailyByMonthAndWeekDay(self):
1144
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1153
def testDailyByMonthAndNWeekDay(self):
1154
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1163
def testDailyByMonthDayAndWeekDay(self):
1164
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1173
def testDailyByMonthAndMonthDayAndWeekDay(self):
1174
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1184
def testDailyByYearDay(self):
1185
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1193
def testDailyByMonthAndYearDay(self):
1194
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1203
def testDailyByWeekNo(self):
1204
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
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,
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)])
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,
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)])
1236
def testDailyByWeekNoAndWeekDayLast(self):
1237
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1246
def testDailyByWeekNoAndWeekDay53(self):
1247
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1256
def testDailyByEaster(self):
1257
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1265
def testDailyByEasterPos(self):
1266
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1274
def testDailyByEasterNeg(self):
1275
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1283
def testDailyByHour(self):
1284
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1292
def testDailyByMinute(self):
1293
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1301
def testDailyBySecond(self):
1302
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1310
def testDailyByHourAndMinute(self):
1311
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1320
def testDailyByHourAndSecond(self):
1321
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1330
def testDailyByMinuteAndSecond(self):
1331
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1340
def testDailyByHourAndMinuteAndSecond(self):
1341
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1351
def testDailyBySetPos(self):
1352
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
1362
def testHourly(self):
1363
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1370
def testHourlyInterval(self):
1371
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1379
def testHourlyIntervalLarge(self):
1380
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1388
def testHourlyByMonth(self):
1389
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1397
def testHourlyByMonthDay(self):
1398
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1406
def testHourlyByMonthAndMonthDay(self):
1407
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1416
def testHourlyByWeekDay(self):
1417
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1425
def testHourlyByNWeekDay(self):
1426
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1434
def testHourlyByMonthAndWeekDay(self):
1435
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1444
def testHourlyByMonthAndNWeekDay(self):
1445
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1454
def testHourlyByMonthDayAndWeekDay(self):
1455
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1464
def testHourlyByMonthAndMonthDayAndWeekDay(self):
1465
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1475
def testHourlyByYearDay(self):
1476
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1484
def testHourlyByMonthAndYearDay(self):
1485
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1494
def testHourlyByWeekNo(self):
1495
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1503
def testHourlyByWeekNoAndWeekDay(self):
1504
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1513
def testHourlyByWeekNoAndWeekDayLarge(self):
1514
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1523
def testHourlyByWeekNoAndWeekDayLast(self):
1524
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1533
def testHourlyByWeekNoAndWeekDay53(self):
1534
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1543
def testHourlyByEaster(self):
1544
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1552
def testHourlyByEasterPos(self):
1553
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1561
def testHourlyByEasterNeg(self):
1562
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1570
def testHourlyByHour(self):
1571
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1579
def testHourlyByMinute(self):
1580
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1588
def testHourlyBySecond(self):
1589
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1597
def testHourlyByHourAndMinute(self):
1598
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1607
def testHourlyByHourAndSecond(self):
1608
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1617
def testHourlyByMinuteAndSecond(self):
1618
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1627
def testHourlyByHourAndMinuteAndSecond(self):
1628
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1638
def testHourlyBySetPos(self):
1639
self.assertEqual(list(rrule(FREQ_HOURLY,
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)])
1649
def testMinutely(self):
1650
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1657
def testMinutelyInterval(self):
1658
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1666
def testMinutelyIntervalLarge(self):
1667
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1675
def testMinutelyByMonth(self):
1676
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1684
def testMinutelyByMonthDay(self):
1685
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1693
def testMinutelyByMonthAndMonthDay(self):
1694
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1703
def testMinutelyByWeekDay(self):
1704
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1712
def testMinutelyByNWeekDay(self):
1713
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1721
def testMinutelyByMonthAndWeekDay(self):
1722
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1731
def testMinutelyByMonthAndNWeekDay(self):
1732
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1741
def testMinutelyByMonthDayAndWeekDay(self):
1742
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1751
def testMinutelyByMonthAndMonthDayAndWeekDay(self):
1752
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1762
def testMinutelyByYearDay(self):
1763
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1771
def testMinutelyByMonthAndYearDay(self):
1772
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1781
def testMinutelyByWeekNo(self):
1782
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1790
def testMinutelyByWeekNoAndWeekDay(self):
1791
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1800
def testMinutelyByWeekNoAndWeekDayLarge(self):
1801
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1810
def testMinutelyByWeekNoAndWeekDayLast(self):
1811
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1820
def testMinutelyByWeekNoAndWeekDay53(self):
1821
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1830
def testMinutelyByEaster(self):
1831
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1839
def testMinutelyByEasterPos(self):
1840
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1848
def testMinutelyByEasterNeg(self):
1849
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1857
def testMinutelyByHour(self):
1858
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1866
def testMinutelyByMinute(self):
1867
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1875
def testMinutelyBySecond(self):
1876
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1884
def testMinutelyByHourAndMinute(self):
1885
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1894
def testMinutelyByHourAndSecond(self):
1895
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1904
def testMinutelyByMinuteAndSecond(self):
1905
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1914
def testMinutelyByHourAndMinuteAndSecond(self):
1915
self.assertEqual(list(rrule(FREQ_MINUTELY,
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)])
1925
def testMinutelyBySetPos(self):
1926
self.assertEqual(list(rrule(FREQ_MINUTELY,
1928
bysecond=(15,30,45),
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)])
1935
def testSecondly(self):
1936
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
1943
def testSecondlyInterval(self):
1944
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
1952
def testSecondlyIntervalLarge(self):
1953
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
1961
def testSecondlyByMonth(self):
1962
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
1970
def testSecondlyByMonthDay(self):
1971
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
1979
def testSecondlyByMonthAndMonthDay(self):
1980
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
1989
def testSecondlyByWeekDay(self):
1990
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
1998
def testSecondlyByNWeekDay(self):
1999
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2007
def testSecondlyByMonthAndWeekDay(self):
2008
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2017
def testSecondlyByMonthAndNWeekDay(self):
2018
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2027
def testSecondlyByMonthDayAndWeekDay(self):
2028
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2037
def testSecondlyByMonthAndMonthDayAndWeekDay(self):
2038
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2048
def testSecondlyByYearDay(self):
2049
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2057
def testSecondlyByMonthAndYearDay(self):
2058
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2067
def testSecondlyByWeekNo(self):
2068
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2076
def testSecondlyByWeekNoAndWeekDay(self):
2077
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2086
def testSecondlyByWeekNoAndWeekDayLarge(self):
2087
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2096
def testSecondlyByWeekNoAndWeekDayLast(self):
2097
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2106
def testSecondlyByWeekNoAndWeekDay53(self):
2107
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2116
def testSecondlyByEaster(self):
2117
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2125
def testSecondlyByEasterPos(self):
2126
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2134
def testSecondlyByEasterNeg(self):
2135
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2143
def testSecondlyByHour(self):
2144
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2152
def testSecondlyByMinute(self):
2153
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2161
def testSecondlyBySecond(self):
2162
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2170
def testSecondlyByHourAndMinute(self):
2171
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2180
def testSecondlyByHourAndSecond(self):
2181
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2190
def testSecondlyByMinuteAndSecond(self):
2191
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2200
def testSecondlyByHourAndMinuteAndSecond(self):
2201
self.assertEqual(list(rrule(FREQ_SECONDLY,
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)])
2211
def testUntilNotMatching(self):
2212
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
2220
def testUntilMatching(self):
2221
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
2229
def testUntilSingle(self):
2230
self.assertEqual(list(rrule(FREQ_DAILY,
2232
dtstart=parse("19970902T090000"),
2233
until=parse("19970902T090000"))),
2234
[datetime(1997, 9, 2, 9, 0)])
2236
def testUntilEmpty(self):
2237
self.assertEqual(list(rrule(FREQ_DAILY,
2239
dtstart=parse("19970902T090000"),
2240
until=parse("19970901T090000"))),
2243
def testUntilWithDate(self):
2244
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
2252
def testWkStIntervalMO(self):
2253
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
2263
def testWkStIntervalSU(self):
2264
self.assertEqual(list(rrule(FREQ_WEEKLY,
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)])
2274
def testDTStartIsDate(self):
2275
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
2282
def testDTStartWithMicroseconds(self):
2283
self.assertEqual(list(rrule(FREQ_DAILY,
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)])
2290
def testMaxYear(self):
2291
self.assertEqual(list(rrule(FREQ_YEARLY,
2295
dtstart=parse("99970902T090000"))),
2298
def testGetItem(self):
2299
self.assertEqual(rrule(FREQ_DAILY,
2301
dtstart=parse("19970902T090000"))[0],
2302
datetime(1997, 9, 2, 9, 0))
2304
def testGetItemNeg(self):
2305
self.assertEqual(rrule(FREQ_DAILY,
2307
dtstart=parse("19970902T090000"))[-1],
2308
datetime(1997, 9, 4, 9, 0))
2310
def testGetItemSlice(self):
2311
self.assertEqual(rrule(FREQ_DAILY,
2313
dtstart=parse("19970902T090000"))[1:2],
2314
[datetime(1997, 9, 3, 9, 0)])
2316
def testGetItemSliceEmpty(self):
2317
self.assertEqual(rrule(FREQ_DAILY,
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)])
2324
def testGetItemSliceStep(self):
2325
self.assertEqual(rrule(FREQ_DAILY,
2327
dtstart=parse("19970902T090000"))[::-2],
2328
[datetime(1997, 9, 4, 9, 0),
2329
datetime(1997, 9, 2, 9, 0)])
2331
def testCount(self):
2332
self.assertEqual(rrule(FREQ_DAILY,
2334
dtstart=parse("19970902T090000")).count(),
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)
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)
2345
def testBefore(self):
2346
self.assertEqual(rrule(FREQ_DAILY,
2348
dtstart=parse("19970902T090000"))
2349
.before(parse("19970905T090000")),
2350
datetime(1997, 9, 4, 9, 0))
2352
def testBeforeInc(self):
2353
self.assertEqual(rrule(FREQ_DAILY,
2355
dtstart=parse("19970902T090000"))
2356
.before(parse("19970905T090000"), inc=True),
2357
datetime(1997, 9, 5, 9, 0))
2359
def testAfter(self):
2360
self.assertEqual(rrule(FREQ_DAILY,
2362
dtstart=parse("19970902T090000"))
2363
.after(parse("19970904T090000")),
2364
datetime(1997, 9, 5, 9, 0))
2366
def testAfterInc(self):
2367
self.assertEqual(rrule(FREQ_DAILY,
2369
dtstart=parse("19970902T090000"))
2370
.after(parse("19970904T090000"), inc=True),
2371
datetime(1997, 9, 4, 9, 0))
2373
def testBetween(self):
2374
self.assertEqual(rrule(FREQ_DAILY,
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)])
2383
def testBetweenInc(self):
2384
self.assertEqual(rrule(FREQ_DAILY,
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)])
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)])
2415
def testCachePost(self):
2416
rr = rrule(FREQ_DAILY, count=15, cache=True,
2417
dtstart=parse("19970902T090000"))
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)])
2436
def testCachePostInternal(self):
2437
rr = rrule(FREQ_DAILY, count=15, cache=True,
2438
dtstart=parse("19970902T090000"))
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)])
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)
2462
def testCachePostContains(self):
2463
rr = rrule(FREQ_DAILY, count=3, cache=True,
2464
dtstart=parse("19970902T090000"))
2466
self.assertEqual(datetime(1997, 9, 3, 9, 0) in rr, True)
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)])
2479
def testSetDate(self):
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)])
2490
def testSetExRule(self):
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)])
2501
def testSetExDate(self):
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)])
2513
def testSetDateAndExDate(self):
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)])
2529
def testSetDateAndExRule(self):
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)])
2544
def testSetCount(self):
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)
2552
def testSetCachePre(self):
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)])
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")))
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)])
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")))
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)])
2588
self.assertEqual(list(rrulestr(
2589
"DTSTART:19970902T090000\n"
2590
"RRULE:FREQ=YEARLY;COUNT=3\n"
2592
[datetime(1997, 9, 2, 9, 0),
2593
datetime(1998, 9, 2, 9, 0),
2594
datetime(1999, 9, 2, 9, 0)])
2596
def testStrType(self):
2597
self.assertEqual(isinstance(rrulestr(
2598
"DTSTART:19970902T090000\n"
2599
"RRULE:FREQ=YEARLY;COUNT=3\n"
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)
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"
2615
def testStrCase(self):
2616
self.assertEqual(list(rrulestr(
2617
"dtstart:19970902T090000\n"
2618
"rrule:freq=yearly;count=3\n"
2620
[datetime(1997, 9, 2, 9, 0),
2621
datetime(1998, 9, 2, 9, 0),
2622
datetime(1999, 9, 2, 9, 0)])
2624
def testStrSpaces(self):
2625
self.assertEqual(list(rrulestr(
2626
" DTSTART:19970902T090000 "
2627
" RRULE:FREQ=YEARLY;COUNT=3 "
2629
[datetime(1997, 9, 2, 9, 0),
2630
datetime(1998, 9, 2, 9, 0),
2631
datetime(1999, 9, 2, 9, 0)])
2633
def testStrSpacesAndLines(self):
2634
self.assertEqual(list(rrulestr(
2635
" DTSTART:19970902T090000 \n"
2637
" RRULE:FREQ=YEARLY;COUNT=3 \n"
2639
[datetime(1997, 9, 2, 9, 0),
2640
datetime(1998, 9, 2, 9, 0),
2641
datetime(1999, 9, 2, 9, 0)])
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)])
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)])
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)])
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"
2673
[datetime(1997, 9, 2, 9, 0),
2674
datetime(1997, 9, 4, 9, 0),
2675
datetime(1997, 9, 9, 9, 0)])
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"
2684
[datetime(1997, 9, 2, 9, 0),
2685
datetime(1997, 9, 4, 9, 0),
2686
datetime(1997, 9, 9, 9, 0)])
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"
2694
[datetime(1997, 9, 2, 9, 0),
2695
datetime(1997, 9, 9, 9, 0),
2696
datetime(1997, 9, 16, 9, 0)])
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"
2706
[datetime(1997, 9, 2, 9, 0),
2707
datetime(1997, 9, 9, 9, 0),
2708
datetime(1997, 9, 16, 9, 0)])
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"
2723
[datetime(1997, 9, 2, 9, 0),
2724
datetime(1997, 9, 9, 9, 0),
2725
datetime(1997, 9, 16, 9, 0)])
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"
2738
[datetime(1997, 9, 2, 9, 0),
2739
datetime(1997, 9, 9, 9, 0),
2740
datetime(1997, 9, 16, 9, 0)])
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"
2749
[datetime(2033, 3, 3, 3, 3, 3),
2750
datetime(2039, 3, 3, 3, 3, 3),
2751
datetime(2072, 3, 3, 3, 3, 3)])
2753
def testStrNWeekDay(self):
2754
self.assertEqual(list(rrulestr(
2755
"DTSTART:19970902T090000\n"
2756
"RRULE:FREQ=YEARLY;COUNT=3;BYDAY=1TU,-1TH\n"
2758
[datetime(1997, 12, 25, 9, 0),
2759
datetime(1998, 1, 6, 9, 0),
2760
datetime(1998, 12, 31, 9, 0)])
2764
class ParserTest(unittest.TestCase):
2766
self.tzinfos = {"BRST": -10800}
2767
self.brsttz = tzoffset("BRST", -10800)
2768
self.default = datetime(2003, 9, 25)
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))
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))
2782
def testDateCommandFormatIgnoreTz(self):
2783
self.assertEqual(parse("Thu Sep 25 10:36:28 BRST 2003",
2785
datetime(2003, 9, 25, 10, 36, 28))
2787
def testDateCommandFormatStrip1(self):
2788
self.assertEqual(parse("Thu Sep 25 10:36:28 2003"),
2789
datetime(2003, 9, 25, 10, 36, 28))
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))
2795
def testDateCommandFormatStrip3(self):
2796
self.assertEqual(parse("Thu Sep 10:36:28", default=self.default),
2797
datetime(2003, 9, 25, 10, 36, 28))
2799
def testDateCommandFormatStrip4(self):
2800
self.assertEqual(parse("Thu 10:36:28", default=self.default),
2801
datetime(2003, 9, 25, 10, 36, 28))
2803
def testDateCommandFormatStrip5(self):
2804
self.assertEqual(parse("Sep 10:36:28", default=self.default),
2805
datetime(2003, 9, 25, 10, 36, 28))
2807
def testDateCommandFormatStrip6(self):
2808
self.assertEqual(parse("10:36:28", default=self.default),
2809
datetime(2003, 9, 25, 10, 36, 28))
2811
def testDateCommandFormatStrip7(self):
2812
self.assertEqual(parse("10:36", default=self.default),
2813
datetime(2003, 9, 25, 10, 36))
2815
def testDateCommandFormatStrip8(self):
2816
self.assertEqual(parse("Thu Sep 25 2003"),
2817
datetime(2003, 9, 25))
2819
def testDateCommandFormatStrip9(self):
2820
self.assertEqual(parse("Sep 25 2003"),
2821
datetime(2003, 9, 25))
2823
def testDateCommandFormatStrip9(self):
2824
self.assertEqual(parse("Sep 2003", default=self.default),
2825
datetime(2003, 9, 25))
2827
def testDateCommandFormatStrip10(self):
2828
self.assertEqual(parse("Sep", default=self.default),
2829
datetime(2003, 9, 25))
2831
def testDateCommandFormatStrip11(self):
2832
self.assertEqual(parse("2003", default=self.default),
2833
datetime(2003, 9, 25))
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))
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))
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))
2850
def testISOFormatStrip2(self):
2851
self.assertEqual(parse("2003-09-25T10:49:41"),
2852
datetime(2003, 9, 25, 10, 49, 41))
2854
def testISOFormatStrip3(self):
2855
self.assertEqual(parse("2003-09-25T10:49"),
2856
datetime(2003, 9, 25, 10, 49))
2858
def testISOFormatStrip4(self):
2859
self.assertEqual(parse("2003-09-25T10"),
2860
datetime(2003, 9, 25, 10))
2862
def testISOFormatStrip5(self):
2863
self.assertEqual(parse("2003-09-25"),
2864
datetime(2003, 9, 25))
2866
def testISOStrippedFormat(self):
2867
self.assertEqual(parse("20030925T104941.5-0300"),
2868
datetime(2003, 9, 25, 10, 49, 41, 500000,
2869
tzinfo=self.brsttz))
2871
def testISOStrippedFormatStrip1(self):
2872
self.assertEqual(parse("20030925T104941-0300"),
2873
datetime(2003, 9, 25, 10, 49, 41,
2874
tzinfo=self.brsttz))
2876
def testISOStrippedFormatStrip2(self):
2877
self.assertEqual(parse("20030925T104941"),
2878
datetime(2003, 9, 25, 10, 49, 41))
2880
def testISOStrippedFormatStrip3(self):
2881
self.assertEqual(parse("20030925T1049"),
2882
datetime(2003, 9, 25, 10, 49, 0))
2884
def testISOStrippedFormatStrip4(self):
2885
self.assertEqual(parse("20030925T10"),
2886
datetime(2003, 9, 25, 10))
2888
def testISOStrippedFormatStrip5(self):
2889
self.assertEqual(parse("20030925"),
2890
datetime(2003, 9, 25))
2892
def testNoSeparator1(self):
2893
self.assertEqual(parse("199709020908"),
2894
datetime(1997, 9, 2, 9, 8))
2896
def testNoSeparator2(self):
2897
self.assertEqual(parse("19970902090807"),
2898
datetime(1997, 9, 2, 9, 8, 7))
2900
def testDateWithDash1(self):
2901
self.assertEqual(parse("2003-09-25"),
2902
datetime(2003, 9, 25))
2904
def testDateWithDash2(self):
2905
self.assertEqual(parse("2003-Sep-25"),
2906
datetime(2003, 9, 25))
2908
def testDateWithDash3(self):
2909
self.assertEqual(parse("25-Sep-2003"),
2910
datetime(2003, 9, 25))
2912
def testDateWithDash4(self):
2913
self.assertEqual(parse("25-Sep-2003"),
2914
datetime(2003, 9, 25))
2916
def testDateWithDash5(self):
2917
self.assertEqual(parse("Sep-25-2003"),
2918
datetime(2003, 9, 25))
2920
def testDateWithDash6(self):
2921
self.assertEqual(parse("09-25-2003"),
2922
datetime(2003, 9, 25))
2924
def testDateWithDash7(self):
2925
self.assertEqual(parse("25-09-2003"),
2926
datetime(2003, 9, 25))
2928
def testDateWithDash8(self):
2929
self.assertEqual(parse("10-09-2003", dayfirst=True),
2930
datetime(2003, 9, 10))
2932
def testDateWithDash9(self):
2933
self.assertEqual(parse("10-09-2003"),
2934
datetime(2003, 10, 9))
2936
def testDateWithDash10(self):
2937
self.assertEqual(parse("10-09-03"),
2938
datetime(2003, 10, 9))
2940
def testDateWithDash11(self):
2941
self.assertEqual(parse("10-09-03", yearfirst=True),
2942
datetime(2010, 9, 3))
2944
def testDateWithDot1(self):
2945
self.assertEqual(parse("2003.09.25"),
2946
datetime(2003, 9, 25))
2948
def testDateWithDot2(self):
2949
self.assertEqual(parse("2003.Sep.25"),
2950
datetime(2003, 9, 25))
2952
def testDateWithDot3(self):
2953
self.assertEqual(parse("25.Sep.2003"),
2954
datetime(2003, 9, 25))
2956
def testDateWithDot4(self):
2957
self.assertEqual(parse("25.Sep.2003"),
2958
datetime(2003, 9, 25))
2960
def testDateWithDot5(self):
2961
self.assertEqual(parse("Sep.25.2003"),
2962
datetime(2003, 9, 25))
2964
def testDateWithDot6(self):
2965
self.assertEqual(parse("09.25.2003"),
2966
datetime(2003, 9, 25))
2968
def testDateWithDot7(self):
2969
self.assertEqual(parse("25.09.2003"),
2970
datetime(2003, 9, 25))
2972
def testDateWithDot8(self):
2973
self.assertEqual(parse("10.09.2003", dayfirst=True),
2974
datetime(2003, 9, 10))
2976
def testDateWithDot9(self):
2977
self.assertEqual(parse("10.09.2003"),
2978
datetime(2003, 10, 9))
2980
def testDateWithDot10(self):
2981
self.assertEqual(parse("10.09.03"),
2982
datetime(2003, 10, 9))
2984
def testDateWithDot11(self):
2985
self.assertEqual(parse("10.09.03", yearfirst=True),
2986
datetime(2010, 9, 3))
2988
def testDateWithSlash1(self):
2989
self.assertEqual(parse("2003/09/25"),
2990
datetime(2003, 9, 25))
2992
def testDateWithSlash2(self):
2993
self.assertEqual(parse("2003/Sep/25"),
2994
datetime(2003, 9, 25))
2996
def testDateWithSlash3(self):
2997
self.assertEqual(parse("25/Sep/2003"),
2998
datetime(2003, 9, 25))
3000
def testDateWithSlash4(self):
3001
self.assertEqual(parse("25/Sep/2003"),
3002
datetime(2003, 9, 25))
3004
def testDateWithSlash5(self):
3005
self.assertEqual(parse("Sep/25/2003"),
3006
datetime(2003, 9, 25))
3008
def testDateWithSlash6(self):
3009
self.assertEqual(parse("09/25/2003"),
3010
datetime(2003, 9, 25))
3012
def testDateWithSlash7(self):
3013
self.assertEqual(parse("25/09/2003"),
3014
datetime(2003, 9, 25))
3016
def testDateWithSlash8(self):
3017
self.assertEqual(parse("10/09/2003", dayfirst=True),
3018
datetime(2003, 9, 10))
3020
def testDateWithSlash9(self):
3021
self.assertEqual(parse("10/09/2003"),
3022
datetime(2003, 10, 9))
3024
def testDateWithSlash10(self):
3025
self.assertEqual(parse("10/09/03"),
3026
datetime(2003, 10, 9))
3028
def testDateWithSlash11(self):
3029
self.assertEqual(parse("10/09/03", yearfirst=True),
3030
datetime(2010, 9, 3))
3032
def testDateWithSpace12(self):
3033
self.assertEqual(parse("25 09 03"),
3034
datetime(2003, 9, 25))
3036
def testDateWithSpace13(self):
3037
self.assertEqual(parse("25 09 03"),
3038
datetime(2003, 9, 25))
3040
def testDateWithSpace1(self):
3041
self.assertEqual(parse("2003 09 25"),
3042
datetime(2003, 9, 25))
3044
def testDateWithSpace2(self):
3045
self.assertEqual(parse("2003 Sep 25"),
3046
datetime(2003, 9, 25))
3048
def testDateWithSpace3(self):
3049
self.assertEqual(parse("25 Sep 2003"),
3050
datetime(2003, 9, 25))
3052
def testDateWithSpace4(self):
3053
self.assertEqual(parse("25 Sep 2003"),
3054
datetime(2003, 9, 25))
3056
def testDateWithSpace5(self):
3057
self.assertEqual(parse("Sep 25 2003"),
3058
datetime(2003, 9, 25))
3060
def testDateWithSpace6(self):
3061
self.assertEqual(parse("09 25 2003"),
3062
datetime(2003, 9, 25))
3064
def testDateWithSpace7(self):
3065
self.assertEqual(parse("25 09 2003"),
3066
datetime(2003, 9, 25))
3068
def testDateWithSpace8(self):
3069
self.assertEqual(parse("10 09 2003", dayfirst=True),
3070
datetime(2003, 9, 10))
3072
def testDateWithSpace9(self):
3073
self.assertEqual(parse("10 09 2003"),
3074
datetime(2003, 10, 9))
3076
def testDateWithSpace10(self):
3077
self.assertEqual(parse("10 09 03"),
3078
datetime(2003, 10, 9))
3080
def testDateWithSpace11(self):
3081
self.assertEqual(parse("10 09 03", yearfirst=True),
3082
datetime(2010, 9, 3))
3084
def testDateWithSpace12(self):
3085
self.assertEqual(parse("25 09 03"),
3086
datetime(2003, 9, 25))
3088
def testDateWithSpace13(self):
3089
self.assertEqual(parse("25 09 03"),
3090
datetime(2003, 9, 25))
3092
def testStrangelyOrderedDate1(self):
3093
self.assertEqual(parse("03 25 Sep"),
3094
datetime(2003, 9, 25))
3096
def testStrangelyOrderedDate2(self):
3097
self.assertEqual(parse("2003 25 Sep"),
3098
datetime(2003, 9, 25))
3100
def testStrangelyOrderedDate3(self):
3101
self.assertEqual(parse("25 03 Sep"),
3102
datetime(2025, 9, 3))
3104
def testHourWithLetters(self):
3105
self.assertEqual(parse("10h36m28.5s", default=self.default),
3106
datetime(2003, 9, 25, 10, 36, 28, 500000))
3108
def testHourWithLettersStrip1(self):
3109
self.assertEqual(parse("10h36m28s", default=self.default),
3110
datetime(2003, 9, 25, 10, 36, 28))
3112
def testHourWithLettersStrip1(self):
3113
self.assertEqual(parse("10h36m", default=self.default),
3114
datetime(2003, 9, 25, 10, 36))
3116
def testHourWithLettersStrip2(self):
3117
self.assertEqual(parse("10h", default=self.default),
3118
datetime(2003, 9, 25, 10))
3120
def testHourAmPm1(self):
3121
self.assertEqual(parse("10h am", default=self.default),
3122
datetime(2003, 9, 25, 10))
3124
def testHourAmPm2(self):
3125
self.assertEqual(parse("10h pm", default=self.default),
3126
datetime(2003, 9, 25, 22))
3128
def testHourAmPm3(self):
3129
self.assertEqual(parse("10am", default=self.default),
3130
datetime(2003, 9, 25, 10))
3132
def testHourAmPm4(self):
3133
self.assertEqual(parse("10pm", default=self.default),
3134
datetime(2003, 9, 25, 22))
3136
def testHourAmPm5(self):
3137
self.assertEqual(parse("10:00 am", default=self.default),
3138
datetime(2003, 9, 25, 10))
3140
def testHourAmPm6(self):
3141
self.assertEqual(parse("10:00 pm", default=self.default),
3142
datetime(2003, 9, 25, 22))
3144
def testHourAmPm7(self):
3145
self.assertEqual(parse("10:00am", default=self.default),
3146
datetime(2003, 9, 25, 10))
3148
def testHourAmPm8(self):
3149
self.assertEqual(parse("10:00pm", default=self.default),
3150
datetime(2003, 9, 25, 22))
3152
def testHourAmPm9(self):
3153
self.assertEqual(parse("10:00a.m", default=self.default),
3154
datetime(2003, 9, 25, 10))
3156
def testHourAmPm10(self):
3157
self.assertEqual(parse("10:00p.m", default=self.default),
3158
datetime(2003, 9, 25, 22))
3160
def testHourAmPm11(self):
3161
self.assertEqual(parse("10:00a.m.", default=self.default),
3162
datetime(2003, 9, 25, 10))
3164
def testHourAmPm12(self):
3165
self.assertEqual(parse("10:00p.m.", default=self.default),
3166
datetime(2003, 9, 25, 22))
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))
3174
def testWeekdayAlone(self):
3175
self.assertEqual(parse("Wed", default=self.default),
3176
datetime(2003, 10, 1))
3178
def testLongWeekday(self):
3179
self.assertEqual(parse("Wednesday", default=self.default),
3180
datetime(2003, 10, 1))
3182
def testLongMonth(self):
3183
self.assertEqual(parse("October", default=self.default),
3184
datetime(2003, 10, 25))
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))
3193
def testExtraSpace(self):
3194
self.assertEqual(parse(" July 4 , 1976 12:01:02 am "),
3195
datetime(1976, 7, 4, 0, 1, 2))
3197
def testRandomFormat1(self):
3198
self.assertEqual(parse("Wed, July 10, '96"),
3199
datetime(1996, 7, 10, 0, 0))
3201
def testRandomFormat2(self):
3202
self.assertEqual(parse("1996.07.10 AD at 15:08:56 PDT",
3204
datetime(1996, 7, 10, 15, 8, 56))
3206
def testRandomFormat3(self):
3207
self.assertEqual(parse("1996.July.10 AD 12:08 PM"),
3208
datetime(1996, 7, 10, 12, 8))
3210
def testRandomFormat4(self):
3211
self.assertEqual(parse("Tuesday, April 12, 1952 AD 3:30:42pm PST",
3213
datetime(1952, 4, 12, 15, 30, 42))
3215
def testRandomFormat5(self):
3216
self.assertEqual(parse("November 5, 1994, 8:15:30 am EST",
3218
datetime(1994, 11, 5, 8, 15, 30))
3220
def testRandomFormat6(self):
3221
self.assertEqual(parse("1994-11-05T08:15:30-05:00",
3223
datetime(1994, 11, 5, 8, 15, 30))
3225
def testRandomFormat7(self):
3226
self.assertEqual(parse("1994-11-05T08:15:30Z",
3228
datetime(1994, 11, 5, 8, 15, 30))
3230
def testRandomFormat8(self):
3231
self.assertEqual(parse("July 4, 1976"), datetime(1976, 7, 4))
3233
def testRandomFormat9(self):
3234
self.assertEqual(parse("7 4 1976"), datetime(1976, 7, 4))
3236
def testRandomFormat10(self):
3237
self.assertEqual(parse("4 jul 1976"), datetime(1976, 7, 4))
3239
def testRandomFormat11(self):
3240
self.assertEqual(parse("7-4-76"), datetime(1976, 7, 4))
3242
def testRandomFormat12(self):
3243
self.assertEqual(parse("19760704"), datetime(1976, 7, 4))
3245
def testRandomFormat13(self):
3246
self.assertEqual(parse("0:01:02", default=self.default),
3247
datetime(2003, 9, 25, 0, 1, 2))
3249
def testRandomFormat14(self):
3250
self.assertEqual(parse("12h 01m02s am", default=self.default),
3251
datetime(2003, 9, 25, 0, 1, 2))
3253
def testRandomFormat15(self):
3254
self.assertEqual(parse("0:01:02 on July 4, 1976"),
3255
datetime(1976, 7, 4, 0, 1, 2))
3257
def testRandomFormat16(self):
3258
self.assertEqual(parse("0:01:02 on July 4, 1976"),
3259
datetime(1976, 7, 4, 0, 1, 2))
3261
def testRandomFormat17(self):
3262
self.assertEqual(parse("1976-07-04T00:01:02Z", ignoretz=True),
3263
datetime(1976, 7, 4, 0, 1, 2))
3265
def testRandomFormat18(self):
3266
self.assertEqual(parse("July 4, 1976 12:01:02 am"),
3267
datetime(1976, 7, 4, 0, 1, 2))
3269
def testRandomFormat19(self):
3270
self.assertEqual(parse("Mon Jan 2 04:24:27 1995"),
3271
datetime(1995, 1, 2, 4, 24, 27))
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))
3277
def testRandomFormat21(self):
3278
self.assertEqual(parse("04.04.95 00:22"),
3279
datetime(1995, 4, 4, 0, 22))
3281
def testRandomFormat22(self):
3282
self.assertEqual(parse("Jan 1 1999 11:23:34.578"),
3283
datetime(1999, 1, 1, 11, 23, 34, 578000))
3285
def testRandomFormat23(self):
3286
self.assertEqual(parse("950404 122212"),
3287
datetime(1995, 4, 4, 12, 22, 12))
3289
def testRandomFormat24(self):
3290
self.assertEqual(parse("0:00 PM, PST", default=self.default,
3292
datetime(2003, 9, 25, 12, 0))
3294
def testRandomFormat25(self):
3295
self.assertEqual(parse("12:08 PM", default=self.default),
3296
datetime(2003, 9, 25, 12, 8))
3298
def testRandomFormat26(self):
3299
self.assertEqual(parse("5:50 A.M. on June 13, 1990"),
3300
datetime(1990, 6, 13, 5, 50))
3302
def testRandomFormat27(self):
3303
self.assertEqual(parse("3rd of May 2001"), datetime(2001, 5, 3))
3305
def testRandomFormat28(self):
3306
self.assertEqual(parse("5th of March 2001"), datetime(2001, 3, 5))
3308
def testRandomFormat29(self):
3309
self.assertEqual(parse("1st of May 2003"), datetime(2003, 5, 1))
3311
def testRandomFormat30(self):
3312
self.assertEqual(parse("01h02m03", default=self.default),
3313
datetime(2003, 9, 25, 1, 2, 3))
3315
def testRandomFormat31(self):
3316
self.assertEqual(parse("01h02", default=self.default),
3317
datetime(2003, 9, 25, 1, 2))
3319
def testRandomFormat32(self):
3320
self.assertEqual(parse("01h02s", default=self.default),
3321
datetime(2003, 9, 25, 1, 0, 2))
3323
def testRandomFormat33(self):
3324
self.assertEqual(parse("01m02", default=self.default),
3325
datetime(2003, 9, 25, 0, 1, 2))
3327
def testRandomFormat34(self):
3328
self.assertEqual(parse("01m02h", default=self.default),
3329
datetime(2003, 9, 25, 2, 1))
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
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)
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)
3349
class EasterTest(unittest.TestCase):
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)),
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)),
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)),
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)),
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)),
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)),
3418
(date(2050, 4, 10), date(2050, 4, 17)),
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))
3426
class TZTest(unittest.TestCase):
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==
3454
TZICAL_EST5EDT = """
3457
LAST-MODIFIED:19870101T000000Z
3458
TZURL:http://zones.stds_r_us.net/tz/US-Eastern
3460
DTSTART:19671029T020000
3461
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
3467
DTSTART:19870405T020000
3468
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
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")
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")
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")
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")
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")
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")
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")
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")
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")
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")
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")
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")
3558
def testStrCmp1(self):
3559
self.assertEqual(tzstr("EST5EDT"),
3560
tzstr("EST5EDT4,M4.1.0/02:00:00,M10-5-0/02:00"))
3562
def testStrCmp2(self):
3563
self.assertEqual(tzstr("EST5EDT"),
3564
tzstr("EST5EDT,4,1,0,7200,10,-1,0,7200,3600"))
3566
def testRangeCmp1(self):
3567
self.assertEqual(tzstr("EST5EDT"),
3568
tzrange("EST", -18000, "EDT", -14400,
3569
relativedelta(hours=+2,
3572
relativedelta(hours=+1,
3576
def testRangeCmp2(self):
3577
self.assertEqual(tzstr("EST5EDT"),
3578
tzrange("EST", -18000, "EDT"))
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")
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")
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")
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")
3600
if __name__ == "__main__":