Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 3950 lines (3437 sloc) 169 KB
#!/usr/bin/python
# -*- encoding: utf-8 -*-
from cStringIO import StringIO
import unittest
import calendar
import time
import base64
import os
# Add build directory to search path
if os.path.exists("build"):
from distutils.util import get_platform
import sys
s = "build/lib.%s-%.3s" % (get_platform(), sys.version)
s = os.path.join(os.getcwd(), s)
sys.path.insert(0,s)
from dateutil.relativedelta import *
from dateutil.parser import *
from dateutil.easter import *
from dateutil.rrule import *
from dateutil.tz import *
from dateutil import zoneinfo
from datetime import *
class RelativeDeltaTest(unittest.TestCase):
now = datetime(2003, 9, 17, 20, 54, 47, 282310)
today = date(2003, 9, 17)
def testNextMonth(self):
self.assertEqual(self.now+relativedelta(months=+1),
datetime(2003, 10, 17, 20, 54, 47, 282310))
def testNextMonthPlusOneWeek(self):
self.assertEqual(self.now+relativedelta(months=+1, weeks=+1),
datetime(2003, 10, 24, 20, 54, 47, 282310))
def testNextMonthPlusOneWeek10am(self):
self.assertEqual(self.today +
relativedelta(months=+1, weeks=+1, hour=10),
datetime(2003, 10, 24, 10, 0))
def testNextMonthPlusOneWeek10amDiff(self):
self.assertEqual(relativedelta(datetime(2003, 10, 24, 10, 0),
self.today),
relativedelta(months=+1, days=+7, hours=+10))
def testOneMonthBeforeOneYear(self):
self.assertEqual(self.now+relativedelta(years=+1, months=-1),
datetime(2004, 8, 17, 20, 54, 47, 282310))
def testMonthsOfDiffNumOfDays(self):
self.assertEqual(date(2003, 1, 27)+relativedelta(months=+1),
date(2003, 2, 27))
self.assertEqual(date(2003, 1, 31)+relativedelta(months=+1),
date(2003, 2, 28))
self.assertEqual(date(2003, 1, 31)+relativedelta(months=+2),
date(2003, 3, 31))
def testMonthsOfDiffNumOfDaysWithYears(self):
self.assertEqual(date(2000, 2, 28)+relativedelta(years=+1),
date(2001, 2, 28))
self.assertEqual(date(2000, 2, 29)+relativedelta(years=+1),
date(2001, 2, 28))
self.assertEqual(date(1999, 2, 28)+relativedelta(years=+1),
date(2000, 2, 28))
self.assertEqual(date(1999, 3, 1)+relativedelta(years=+1),
date(2000, 3, 1))
self.assertEqual(date(1999, 3, 1)+relativedelta(years=+1),
date(2000, 3, 1))
self.assertEqual(date(2001, 2, 28)+relativedelta(years=-1),
date(2000, 2, 28))
self.assertEqual(date(2001, 3, 1)+relativedelta(years=-1),
date(2000, 3, 1))
def testNextFriday(self):
self.assertEqual(self.today+relativedelta(weekday=FR),
date(2003, 9, 19))
def testNextFridayInt(self):
self.assertEqual(self.today+relativedelta(weekday=calendar.FRIDAY),
date(2003, 9, 19))
def testLastFridayInThisMonth(self):
self.assertEqual(self.today+relativedelta(day=31, weekday=FR(-1)),
date(2003, 9, 26))
def testNextWednesdayIsToday(self):
self.assertEqual(self.today+relativedelta(weekday=WE),
date(2003, 9, 17))
def testNextWenesdayNotToday(self):
self.assertEqual(self.today+relativedelta(days=+1, weekday=WE),
date(2003, 9, 24))
def test15thISOYearWeek(self):
self.assertEqual(date(2003, 1, 1) +
relativedelta(day=4, weeks=+14, weekday=MO(-1)),
date(2003, 4, 7))
def testMillenniumAge(self):
self.assertEqual(relativedelta(self.now, date(2001,1,1)),
relativedelta(years=+2, months=+8, days=+16,
hours=+20, minutes=+54, seconds=+47,
microseconds=+282310))
def testJohnAge(self):
self.assertEqual(relativedelta(self.now,
datetime(1978, 4, 5, 12, 0)),
relativedelta(years=+25, months=+5, days=+12,
hours=+8, minutes=+54, seconds=+47,
microseconds=+282310))
def testJohnAgeWithDate(self):
self.assertEqual(relativedelta(self.today,
datetime(1978, 4, 5, 12, 0)),
relativedelta(years=+25, months=+5, days=+11,
hours=+12))
def testYearDay(self):
self.assertEqual(date(2003, 1, 1)+relativedelta(yearday=260),
date(2003, 9, 17))
self.assertEqual(date(2002, 1, 1)+relativedelta(yearday=260),
date(2002, 9, 17))
self.assertEqual(date(2000, 1, 1)+relativedelta(yearday=260),
date(2000, 9, 16))
self.assertEqual(self.today+relativedelta(yearday=261),
date(2003, 9, 18))
def testNonLeapYearDay(self):
self.assertEqual(date(2003, 1, 1)+relativedelta(nlyearday=260),
date(2003, 9, 17))
self.assertEqual(date(2002, 1, 1)+relativedelta(nlyearday=260),
date(2002, 9, 17))
self.assertEqual(date(2000, 1, 1)+relativedelta(nlyearday=260),
date(2000, 9, 17))
self.assertEqual(self.today+relativedelta(yearday=261),
date(2003, 9, 18))
class RRuleTest(unittest.TestCase):
def testYearly(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1998, 9, 2, 9, 0),
datetime(1999, 9, 2, 9, 0)])
def testYearlyInterval(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
interval=2,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1999, 9, 2, 9, 0),
datetime(2001, 9, 2, 9, 0)])
def testYearlyIntervalLarge(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
interval=100,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(2097, 9, 2, 9, 0),
datetime(2197, 9, 2, 9, 0)])
def testYearlyByMonth(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
bymonth=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 2, 9, 0),
datetime(1998, 3, 2, 9, 0),
datetime(1999, 1, 2, 9, 0)])
def testYearlyByMonthDay(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
bymonthday=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 3, 9, 0),
datetime(1997, 10, 1, 9, 0),
datetime(1997, 10, 3, 9, 0)])
def testYearlyByMonthAndMonthDay(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
bymonth=(1,3),
bymonthday=(5,7),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 5, 9, 0),
datetime(1998, 1, 7, 9, 0),
datetime(1998, 3, 5, 9, 0)])
def testYearlyByWeekDay(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testYearlyByNWeekDay(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 25, 9, 0),
datetime(1998, 1, 6, 9, 0),
datetime(1998, 12, 31, 9, 0)])
def testYearlyByNWeekDayLarge(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byweekday=(TU(3),TH(-3)),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 11, 9, 0),
datetime(1998, 1, 20, 9, 0),
datetime(1998, 12, 17, 9, 0)])
def testYearlyByMonthAndWeekDay(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
bymonth=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 1, 6, 9, 0),
datetime(1998, 1, 8, 9, 0)])
def testYearlyByMonthAndNWeekDay(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
bymonth=(1,3),
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 6, 9, 0),
datetime(1998, 1, 29, 9, 0),
datetime(1998, 3, 3, 9, 0)])
def testYearlyByMonthAndNWeekDayLarge(self):
# This is interesting because the TH(-3) ends up before
# the TU(3).
self.assertEqual(list(rrule(YEARLY,
count=3,
bymonth=(1,3),
byweekday=(TU(3),TH(-3)),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 15, 9, 0),
datetime(1998, 1, 20, 9, 0),
datetime(1998, 3, 12, 9, 0)])
def testYearlyByMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 2, 3, 9, 0),
datetime(1998, 3, 3, 9, 0)])
def testYearlyByMonthAndMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
bymonth=(1,3),
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 3, 3, 9, 0),
datetime(2001, 3, 1, 9, 0)])
def testYearlyByYearDay(self):
self.assertEqual(list(rrule(YEARLY,
count=4,
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 9, 0),
datetime(1998, 1, 1, 9, 0),
datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0)])
def testYearlyByYearDayNeg(self):
self.assertEqual(list(rrule(YEARLY,
count=4,
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 9, 0),
datetime(1998, 1, 1, 9, 0),
datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0)])
def testYearlyByMonthAndYearDay(self):
self.assertEqual(list(rrule(YEARLY,
count=4,
bymonth=(4,7),
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0),
datetime(1999, 4, 10, 9, 0),
datetime(1999, 7, 19, 9, 0)])
def testYearlyByMonthAndYearDayNeg(self):
self.assertEqual(list(rrule(YEARLY,
count=4,
bymonth=(4,7),
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0),
datetime(1999, 4, 10, 9, 0),
datetime(1999, 7, 19, 9, 0)])
def testYearlyByWeekNo(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byweekno=20,
dtstart=parse("19970902T090000"))),
[datetime(1998, 5, 11, 9, 0),
datetime(1998, 5, 12, 9, 0),
datetime(1998, 5, 13, 9, 0)])
def testYearlyByWeekNoAndWeekDay(self):
# That's a nice one. The first days of week number one
# may be in the last year.
self.assertEqual(list(rrule(YEARLY,
count=3,
byweekno=1,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 29, 9, 0),
datetime(1999, 1, 4, 9, 0),
datetime(2000, 1, 3, 9, 0)])
def testYearlyByWeekNoAndWeekDayLarge(self):
# Another nice test. The last days of week number 52/53
# may be in the next year.
self.assertEqual(list(rrule(YEARLY,
count=3,
byweekno=52,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 9, 0),
datetime(1998, 12, 27, 9, 0),
datetime(2000, 1, 2, 9, 0)])
def testYearlyByWeekNoAndWeekDayLast(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byweekno=-1,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 9, 0),
datetime(1999, 1, 3, 9, 0),
datetime(2000, 1, 2, 9, 0)])
def testYearlyByEaster(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byeaster=0,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 12, 9, 0),
datetime(1999, 4, 4, 9, 0),
datetime(2000, 4, 23, 9, 0)])
def testYearlyByEasterPos(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byeaster=1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 13, 9, 0),
datetime(1999, 4, 5, 9, 0),
datetime(2000, 4, 24, 9, 0)])
def testYearlyByEasterNeg(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byeaster=-1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 11, 9, 0),
datetime(1999, 4, 3, 9, 0),
datetime(2000, 4, 22, 9, 0)])
def testYearlyByWeekNoAndWeekDay53(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byweekno=53,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1998, 12, 28, 9, 0),
datetime(2004, 12, 27, 9, 0),
datetime(2009, 12, 28, 9, 0)])
def testYearlyByWeekNoAndWeekDay53(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byweekno=53,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1998, 12, 28, 9, 0),
datetime(2004, 12, 27, 9, 0),
datetime(2009, 12, 28, 9, 0)])
def testYearlyByHour(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byhour=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0),
datetime(1998, 9, 2, 6, 0),
datetime(1998, 9, 2, 18, 0)])
def testYearlyByMinute(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6),
datetime(1997, 9, 2, 9, 18),
datetime(1998, 9, 2, 9, 6)])
def testYearlyBySecond(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 6),
datetime(1997, 9, 2, 9, 0, 18),
datetime(1998, 9, 2, 9, 0, 6)])
def testYearlyByHourAndMinute(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byhour=(6,18),
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6),
datetime(1997, 9, 2, 18, 18),
datetime(1998, 9, 2, 6, 6)])
def testYearlyByHourAndSecond(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byhour=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0, 6),
datetime(1997, 9, 2, 18, 0, 18),
datetime(1998, 9, 2, 6, 0, 6)])
def testYearlyByMinuteAndSecond(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6, 6),
datetime(1997, 9, 2, 9, 6, 18),
datetime(1997, 9, 2, 9, 18, 6)])
def testYearlyByHourAndMinuteAndSecond(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
byhour=(6,18),
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6, 6),
datetime(1997, 9, 2, 18, 6, 18),
datetime(1997, 9, 2, 18, 18, 6)])
def testYearlyBySetPos(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
bymonthday=15,
byhour=(6,18),
bysetpos=(3,-3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 11, 15, 18, 0),
datetime(1998, 2, 15, 6, 0),
datetime(1998, 11, 15, 18, 0)])
def testMonthly(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 10, 2, 9, 0),
datetime(1997, 11, 2, 9, 0)])
def testMonthlyInterval(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
interval=2,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 11, 2, 9, 0),
datetime(1998, 1, 2, 9, 0)])
def testMonthlyIntervalLarge(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
interval=18,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1999, 3, 2, 9, 0),
datetime(2000, 9, 2, 9, 0)])
def testMonthlyByMonth(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
bymonth=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 2, 9, 0),
datetime(1998, 3, 2, 9, 0),
datetime(1999, 1, 2, 9, 0)])
def testMonthlyByMonthDay(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
bymonthday=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 3, 9, 0),
datetime(1997, 10, 1, 9, 0),
datetime(1997, 10, 3, 9, 0)])
def testMonthlyByMonthAndMonthDay(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
bymonth=(1,3),
bymonthday=(5,7),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 5, 9, 0),
datetime(1998, 1, 7, 9, 0),
datetime(1998, 3, 5, 9, 0)])
def testMonthlyByWeekDay(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testMonthlyByNWeekDay(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 25, 9, 0),
datetime(1997, 10, 7, 9, 0)])
def testMonthlyByNWeekDayLarge(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byweekday=(TU(3),TH(-3)),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 11, 9, 0),
datetime(1997, 9, 16, 9, 0),
datetime(1997, 10, 16, 9, 0)])
def testMonthlyByMonthAndWeekDay(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
bymonth=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 1, 6, 9, 0),
datetime(1998, 1, 8, 9, 0)])
def testMonthlyByMonthAndNWeekDay(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
bymonth=(1,3),
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 6, 9, 0),
datetime(1998, 1, 29, 9, 0),
datetime(1998, 3, 3, 9, 0)])
def testMonthlyByMonthAndNWeekDayLarge(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
bymonth=(1,3),
byweekday=(TU(3),TH(-3)),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 15, 9, 0),
datetime(1998, 1, 20, 9, 0),
datetime(1998, 3, 12, 9, 0)])
def testMonthlyByMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 2, 3, 9, 0),
datetime(1998, 3, 3, 9, 0)])
def testMonthlyByMonthAndMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
bymonth=(1,3),
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 3, 3, 9, 0),
datetime(2001, 3, 1, 9, 0)])
def testMonthlyByYearDay(self):
self.assertEqual(list(rrule(MONTHLY,
count=4,
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 9, 0),
datetime(1998, 1, 1, 9, 0),
datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0)])
def testMonthlyByYearDayNeg(self):
self.assertEqual(list(rrule(MONTHLY,
count=4,
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 9, 0),
datetime(1998, 1, 1, 9, 0),
datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0)])
def testMonthlyByMonthAndYearDay(self):
self.assertEqual(list(rrule(MONTHLY,
count=4,
bymonth=(4,7),
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0),
datetime(1999, 4, 10, 9, 0),
datetime(1999, 7, 19, 9, 0)])
def testMonthlyByMonthAndYearDayNeg(self):
self.assertEqual(list(rrule(MONTHLY,
count=4,
bymonth=(4,7),
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0),
datetime(1999, 4, 10, 9, 0),
datetime(1999, 7, 19, 9, 0)])
def testMonthlyByWeekNo(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byweekno=20,
dtstart=parse("19970902T090000"))),
[datetime(1998, 5, 11, 9, 0),
datetime(1998, 5, 12, 9, 0),
datetime(1998, 5, 13, 9, 0)])
def testMonthlyByWeekNoAndWeekDay(self):
# That's a nice one. The first days of week number one
# may be in the last year.
self.assertEqual(list(rrule(MONTHLY,
count=3,
byweekno=1,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 29, 9, 0),
datetime(1999, 1, 4, 9, 0),
datetime(2000, 1, 3, 9, 0)])
def testMonthlyByWeekNoAndWeekDayLarge(self):
# Another nice test. The last days of week number 52/53
# may be in the next year.
self.assertEqual(list(rrule(MONTHLY,
count=3,
byweekno=52,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 9, 0),
datetime(1998, 12, 27, 9, 0),
datetime(2000, 1, 2, 9, 0)])
def testMonthlyByWeekNoAndWeekDayLast(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byweekno=-1,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 9, 0),
datetime(1999, 1, 3, 9, 0),
datetime(2000, 1, 2, 9, 0)])
def testMonthlyByWeekNoAndWeekDay53(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byweekno=53,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1998, 12, 28, 9, 0),
datetime(2004, 12, 27, 9, 0),
datetime(2009, 12, 28, 9, 0)])
def testMonthlyByEaster(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byeaster=0,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 12, 9, 0),
datetime(1999, 4, 4, 9, 0),
datetime(2000, 4, 23, 9, 0)])
def testMonthlyByEasterPos(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byeaster=1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 13, 9, 0),
datetime(1999, 4, 5, 9, 0),
datetime(2000, 4, 24, 9, 0)])
def testMonthlyByEasterNeg(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byeaster=-1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 11, 9, 0),
datetime(1999, 4, 3, 9, 0),
datetime(2000, 4, 22, 9, 0)])
def testMonthlyByHour(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byhour=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0),
datetime(1997, 10, 2, 6, 0),
datetime(1997, 10, 2, 18, 0)])
def testMonthlyByMinute(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6),
datetime(1997, 9, 2, 9, 18),
datetime(1997, 10, 2, 9, 6)])
def testMonthlyBySecond(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 6),
datetime(1997, 9, 2, 9, 0, 18),
datetime(1997, 10, 2, 9, 0, 6)])
def testMonthlyByHourAndMinute(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byhour=(6,18),
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6),
datetime(1997, 9, 2, 18, 18),
datetime(1997, 10, 2, 6, 6)])
def testMonthlyByHourAndSecond(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byhour=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0, 6),
datetime(1997, 9, 2, 18, 0, 18),
datetime(1997, 10, 2, 6, 0, 6)])
def testMonthlyByMinuteAndSecond(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6, 6),
datetime(1997, 9, 2, 9, 6, 18),
datetime(1997, 9, 2, 9, 18, 6)])
def testMonthlyByHourAndMinuteAndSecond(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
byhour=(6,18),
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6, 6),
datetime(1997, 9, 2, 18, 6, 18),
datetime(1997, 9, 2, 18, 18, 6)])
def testMonthlyBySetPos(self):
self.assertEqual(list(rrule(MONTHLY,
count=3,
bymonthday=(13,17),
byhour=(6,18),
bysetpos=(3,-3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 13, 18, 0),
datetime(1997, 9, 17, 6, 0),
datetime(1997, 10, 13, 18, 0)])
def testWeekly(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testWeeklyInterval(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
interval=2,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 16, 9, 0),
datetime(1997, 9, 30, 9, 0)])
def testWeeklyIntervalLarge(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
interval=20,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1998, 1, 20, 9, 0),
datetime(1998, 6, 9, 9, 0)])
def testWeeklyByMonth(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
bymonth=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 6, 9, 0),
datetime(1998, 1, 13, 9, 0),
datetime(1998, 1, 20, 9, 0)])
def testWeeklyByMonthDay(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
bymonthday=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 3, 9, 0),
datetime(1997, 10, 1, 9, 0),
datetime(1997, 10, 3, 9, 0)])
def testWeeklyByMonthAndMonthDay(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
bymonth=(1,3),
bymonthday=(5,7),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 5, 9, 0),
datetime(1998, 1, 7, 9, 0),
datetime(1998, 3, 5, 9, 0)])
def testWeeklyByWeekDay(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testWeeklyByNWeekDay(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testWeeklyByMonthAndWeekDay(self):
# This test is interesting, because it crosses the year
# boundary in a weekly period to find day '1' as a
# valid recurrence.
self.assertEqual(list(rrule(WEEKLY,
count=3,
bymonth=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 1, 6, 9, 0),
datetime(1998, 1, 8, 9, 0)])
def testWeeklyByMonthAndNWeekDay(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
bymonth=(1,3),
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 1, 6, 9, 0),
datetime(1998, 1, 8, 9, 0)])
def testWeeklyByMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 2, 3, 9, 0),
datetime(1998, 3, 3, 9, 0)])
def testWeeklyByMonthAndMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
bymonth=(1,3),
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 3, 3, 9, 0),
datetime(2001, 3, 1, 9, 0)])
def testWeeklyByYearDay(self):
self.assertEqual(list(rrule(WEEKLY,
count=4,
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 9, 0),
datetime(1998, 1, 1, 9, 0),
datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0)])
def testWeeklyByYearDayNeg(self):
self.assertEqual(list(rrule(WEEKLY,
count=4,
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 9, 0),
datetime(1998, 1, 1, 9, 0),
datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0)])
def testWeeklyByMonthAndYearDay(self):
self.assertEqual(list(rrule(WEEKLY,
count=4,
bymonth=(1,7),
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 7, 19, 9, 0),
datetime(1999, 1, 1, 9, 0),
datetime(1999, 7, 19, 9, 0)])
def testWeeklyByMonthAndYearDayNeg(self):
self.assertEqual(list(rrule(WEEKLY,
count=4,
bymonth=(1,7),
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 7, 19, 9, 0),
datetime(1999, 1, 1, 9, 0),
datetime(1999, 7, 19, 9, 0)])
def testWeeklyByWeekNo(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byweekno=20,
dtstart=parse("19970902T090000"))),
[datetime(1998, 5, 11, 9, 0),
datetime(1998, 5, 12, 9, 0),
datetime(1998, 5, 13, 9, 0)])
def testWeeklyByWeekNoAndWeekDay(self):
# That's a nice one. The first days of week number one
# may be in the last year.
self.assertEqual(list(rrule(WEEKLY,
count=3,
byweekno=1,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 29, 9, 0),
datetime(1999, 1, 4, 9, 0),
datetime(2000, 1, 3, 9, 0)])
def testWeeklyByWeekNoAndWeekDayLarge(self):
# Another nice test. The last days of week number 52/53
# may be in the next year.
self.assertEqual(list(rrule(WEEKLY,
count=3,
byweekno=52,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 9, 0),
datetime(1998, 12, 27, 9, 0),
datetime(2000, 1, 2, 9, 0)])
def testWeeklyByWeekNoAndWeekDayLast(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byweekno=-1,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 9, 0),
datetime(1999, 1, 3, 9, 0),
datetime(2000, 1, 2, 9, 0)])
def testWeeklyByWeekNoAndWeekDay53(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byweekno=53,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1998, 12, 28, 9, 0),
datetime(2004, 12, 27, 9, 0),
datetime(2009, 12, 28, 9, 0)])
def testWeeklyByEaster(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byeaster=0,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 12, 9, 0),
datetime(1999, 4, 4, 9, 0),
datetime(2000, 4, 23, 9, 0)])
def testWeeklyByEasterPos(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byeaster=1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 13, 9, 0),
datetime(1999, 4, 5, 9, 0),
datetime(2000, 4, 24, 9, 0)])
def testWeeklyByEasterNeg(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byeaster=-1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 11, 9, 0),
datetime(1999, 4, 3, 9, 0),
datetime(2000, 4, 22, 9, 0)])
def testWeeklyByHour(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byhour=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0),
datetime(1997, 9, 9, 6, 0),
datetime(1997, 9, 9, 18, 0)])
def testWeeklyByMinute(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6),
datetime(1997, 9, 2, 9, 18),
datetime(1997, 9, 9, 9, 6)])
def testWeeklyBySecond(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 6),
datetime(1997, 9, 2, 9, 0, 18),
datetime(1997, 9, 9, 9, 0, 6)])
def testWeeklyByHourAndMinute(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byhour=(6,18),
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6),
datetime(1997, 9, 2, 18, 18),
datetime(1997, 9, 9, 6, 6)])
def testWeeklyByHourAndSecond(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byhour=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0, 6),
datetime(1997, 9, 2, 18, 0, 18),
datetime(1997, 9, 9, 6, 0, 6)])
def testWeeklyByMinuteAndSecond(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6, 6),
datetime(1997, 9, 2, 9, 6, 18),
datetime(1997, 9, 2, 9, 18, 6)])
def testWeeklyByHourAndMinuteAndSecond(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byhour=(6,18),
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6, 6),
datetime(1997, 9, 2, 18, 6, 18),
datetime(1997, 9, 2, 18, 18, 6)])
def testWeeklyBySetPos(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
byweekday=(TU,TH),
byhour=(6,18),
bysetpos=(3,-3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0),
datetime(1997, 9, 4, 6, 0),
datetime(1997, 9, 9, 18, 0)])
def testDaily(self):
self.assertEqual(list(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 3, 9, 0),
datetime(1997, 9, 4, 9, 0)])
def testDailyInterval(self):
self.assertEqual(list(rrule(DAILY,
count=3,
interval=2,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 6, 9, 0)])
def testDailyIntervalLarge(self):
self.assertEqual(list(rrule(DAILY,
count=3,
interval=92,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 12, 3, 9, 0),
datetime(1998, 3, 5, 9, 0)])
def testDailyByMonth(self):
self.assertEqual(list(rrule(DAILY,
count=3,
bymonth=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 1, 2, 9, 0),
datetime(1998, 1, 3, 9, 0)])
def testDailyByMonthDay(self):
self.assertEqual(list(rrule(DAILY,
count=3,
bymonthday=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 3, 9, 0),
datetime(1997, 10, 1, 9, 0),
datetime(1997, 10, 3, 9, 0)])
def testDailyByMonthAndMonthDay(self):
self.assertEqual(list(rrule(DAILY,
count=3,
bymonth=(1,3),
bymonthday=(5,7),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 5, 9, 0),
datetime(1998, 1, 7, 9, 0),
datetime(1998, 3, 5, 9, 0)])
def testDailyByWeekDay(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testDailyByNWeekDay(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testDailyByMonthAndWeekDay(self):
self.assertEqual(list(rrule(DAILY,
count=3,
bymonth=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 1, 6, 9, 0),
datetime(1998, 1, 8, 9, 0)])
def testDailyByMonthAndNWeekDay(self):
self.assertEqual(list(rrule(DAILY,
count=3,
bymonth=(1,3),
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 1, 6, 9, 0),
datetime(1998, 1, 8, 9, 0)])
def testDailyByMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(DAILY,
count=3,
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 2, 3, 9, 0),
datetime(1998, 3, 3, 9, 0)])
def testDailyByMonthAndMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(DAILY,
count=3,
bymonth=(1,3),
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 3, 3, 9, 0),
datetime(2001, 3, 1, 9, 0)])
def testDailyByYearDay(self):
self.assertEqual(list(rrule(DAILY,
count=4,
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 9, 0),
datetime(1998, 1, 1, 9, 0),
datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0)])
def testDailyByYearDayNeg(self):
self.assertEqual(list(rrule(DAILY,
count=4,
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 9, 0),
datetime(1998, 1, 1, 9, 0),
datetime(1998, 4, 10, 9, 0),
datetime(1998, 7, 19, 9, 0)])
def testDailyByMonthAndYearDay(self):
self.assertEqual(list(rrule(DAILY,
count=4,
bymonth=(1,7),
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 7, 19, 9, 0),
datetime(1999, 1, 1, 9, 0),
datetime(1999, 7, 19, 9, 0)])
def testDailyByMonthAndYearDayNeg(self):
self.assertEqual(list(rrule(DAILY,
count=4,
bymonth=(1,7),
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 9, 0),
datetime(1998, 7, 19, 9, 0),
datetime(1999, 1, 1, 9, 0),
datetime(1999, 7, 19, 9, 0)])
def testDailyByWeekNo(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byweekno=20,
dtstart=parse("19970902T090000"))),
[datetime(1998, 5, 11, 9, 0),
datetime(1998, 5, 12, 9, 0),
datetime(1998, 5, 13, 9, 0)])
def testDailyByWeekNoAndWeekDay(self):
# That's a nice one. The first days of week number one
# may be in the last year.
self.assertEqual(list(rrule(DAILY,
count=3,
byweekno=1,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 29, 9, 0),
datetime(1999, 1, 4, 9, 0),
datetime(2000, 1, 3, 9, 0)])
def testDailyByWeekNoAndWeekDayLarge(self):
# Another nice test. The last days of week number 52/53
# may be in the next year.
self.assertEqual(list(rrule(DAILY,
count=3,
byweekno=52,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 9, 0),
datetime(1998, 12, 27, 9, 0),
datetime(2000, 1, 2, 9, 0)])
def testDailyByWeekNoAndWeekDayLast(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byweekno=-1,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 9, 0),
datetime(1999, 1, 3, 9, 0),
datetime(2000, 1, 2, 9, 0)])
def testDailyByWeekNoAndWeekDay53(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byweekno=53,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1998, 12, 28, 9, 0),
datetime(2004, 12, 27, 9, 0),
datetime(2009, 12, 28, 9, 0)])
def testDailyByEaster(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byeaster=0,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 12, 9, 0),
datetime(1999, 4, 4, 9, 0),
datetime(2000, 4, 23, 9, 0)])
def testDailyByEasterPos(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byeaster=1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 13, 9, 0),
datetime(1999, 4, 5, 9, 0),
datetime(2000, 4, 24, 9, 0)])
def testDailyByEasterNeg(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byeaster=-1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 11, 9, 0),
datetime(1999, 4, 3, 9, 0),
datetime(2000, 4, 22, 9, 0)])
def testDailyByHour(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byhour=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0),
datetime(1997, 9, 3, 6, 0),
datetime(1997, 9, 3, 18, 0)])
def testDailyByMinute(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6),
datetime(1997, 9, 2, 9, 18),
datetime(1997, 9, 3, 9, 6)])
def testDailyBySecond(self):
self.assertEqual(list(rrule(DAILY,
count=3,
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 6),
datetime(1997, 9, 2, 9, 0, 18),
datetime(1997, 9, 3, 9, 0, 6)])
def testDailyByHourAndMinute(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byhour=(6,18),
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6),
datetime(1997, 9, 2, 18, 18),
datetime(1997, 9, 3, 6, 6)])
def testDailyByHourAndSecond(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byhour=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0, 6),
datetime(1997, 9, 2, 18, 0, 18),
datetime(1997, 9, 3, 6, 0, 6)])
def testDailyByMinuteAndSecond(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6, 6),
datetime(1997, 9, 2, 9, 6, 18),
datetime(1997, 9, 2, 9, 18, 6)])
def testDailyByHourAndMinuteAndSecond(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byhour=(6,18),
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6, 6),
datetime(1997, 9, 2, 18, 6, 18),
datetime(1997, 9, 2, 18, 18, 6)])
def testDailyBySetPos(self):
self.assertEqual(list(rrule(DAILY,
count=3,
byhour=(6,18),
byminute=(15,45),
bysetpos=(3,-3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 15),
datetime(1997, 9, 3, 6, 45),
datetime(1997, 9, 3, 18, 15)])
def testHourly(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 2, 10, 0),
datetime(1997, 9, 2, 11, 0)])
def testHourlyInterval(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
interval=2,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 2, 11, 0),
datetime(1997, 9, 2, 13, 0)])
def testHourlyIntervalLarge(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
interval=769,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 10, 4, 10, 0),
datetime(1997, 11, 5, 11, 0)])
def testHourlyByMonth(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
bymonth=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0),
datetime(1998, 1, 1, 1, 0),
datetime(1998, 1, 1, 2, 0)])
def testHourlyByMonthDay(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
bymonthday=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 3, 0, 0),
datetime(1997, 9, 3, 1, 0),
datetime(1997, 9, 3, 2, 0)])
def testHourlyByMonthAndMonthDay(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
bymonth=(1,3),
bymonthday=(5,7),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 5, 0, 0),
datetime(1998, 1, 5, 1, 0),
datetime(1998, 1, 5, 2, 0)])
def testHourlyByWeekDay(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 2, 10, 0),
datetime(1997, 9, 2, 11, 0)])
def testHourlyByNWeekDay(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 2, 10, 0),
datetime(1997, 9, 2, 11, 0)])
def testHourlyByMonthAndWeekDay(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
bymonth=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0),
datetime(1998, 1, 1, 1, 0),
datetime(1998, 1, 1, 2, 0)])
def testHourlyByMonthAndNWeekDay(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
bymonth=(1,3),
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0),
datetime(1998, 1, 1, 1, 0),
datetime(1998, 1, 1, 2, 0)])
def testHourlyByMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0),
datetime(1998, 1, 1, 1, 0),
datetime(1998, 1, 1, 2, 0)])
def testHourlyByMonthAndMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
bymonth=(1,3),
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0),
datetime(1998, 1, 1, 1, 0),
datetime(1998, 1, 1, 2, 0)])
def testHourlyByYearDay(self):
self.assertEqual(list(rrule(HOURLY,
count=4,
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 0, 0),
datetime(1997, 12, 31, 1, 0),
datetime(1997, 12, 31, 2, 0),
datetime(1997, 12, 31, 3, 0)])
def testHourlyByYearDayNeg(self):
self.assertEqual(list(rrule(HOURLY,
count=4,
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 0, 0),
datetime(1997, 12, 31, 1, 0),
datetime(1997, 12, 31, 2, 0),
datetime(1997, 12, 31, 3, 0)])
def testHourlyByMonthAndYearDay(self):
self.assertEqual(list(rrule(HOURLY,
count=4,
bymonth=(4,7),
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 10, 0, 0),
datetime(1998, 4, 10, 1, 0),
datetime(1998, 4, 10, 2, 0),
datetime(1998, 4, 10, 3, 0)])
def testHourlyByMonthAndYearDayNeg(self):
self.assertEqual(list(rrule(HOURLY,
count=4,
bymonth=(4,7),
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 10, 0, 0),
datetime(1998, 4, 10, 1, 0),
datetime(1998, 4, 10, 2, 0),
datetime(1998, 4, 10, 3, 0)])
def testHourlyByWeekNo(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byweekno=20,
dtstart=parse("19970902T090000"))),
[datetime(1998, 5, 11, 0, 0),
datetime(1998, 5, 11, 1, 0),
datetime(1998, 5, 11, 2, 0)])
def testHourlyByWeekNoAndWeekDay(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byweekno=1,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 29, 0, 0),
datetime(1997, 12, 29, 1, 0),
datetime(1997, 12, 29, 2, 0)])
def testHourlyByWeekNoAndWeekDayLarge(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byweekno=52,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 0, 0),
datetime(1997, 12, 28, 1, 0),
datetime(1997, 12, 28, 2, 0)])
def testHourlyByWeekNoAndWeekDayLast(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byweekno=-1,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 0, 0),
datetime(1997, 12, 28, 1, 0),
datetime(1997, 12, 28, 2, 0)])
def testHourlyByWeekNoAndWeekDay53(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byweekno=53,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1998, 12, 28, 0, 0),
datetime(1998, 12, 28, 1, 0),
datetime(1998, 12, 28, 2, 0)])
def testHourlyByEaster(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byeaster=0,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 12, 0, 0),
datetime(1998, 4, 12, 1, 0),
datetime(1998, 4, 12, 2, 0)])
def testHourlyByEasterPos(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byeaster=1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 13, 0, 0),
datetime(1998, 4, 13, 1, 0),
datetime(1998, 4, 13, 2, 0)])
def testHourlyByEasterNeg(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byeaster=-1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 11, 0, 0),
datetime(1998, 4, 11, 1, 0),
datetime(1998, 4, 11, 2, 0)])
def testHourlyByHour(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byhour=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0),
datetime(1997, 9, 3, 6, 0),
datetime(1997, 9, 3, 18, 0)])
def testHourlyByMinute(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6),
datetime(1997, 9, 2, 9, 18),
datetime(1997, 9, 2, 10, 6)])
def testHourlyBySecond(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 6),
datetime(1997, 9, 2, 9, 0, 18),
datetime(1997, 9, 2, 10, 0, 6)])
def testHourlyByHourAndMinute(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byhour=(6,18),
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6),
datetime(1997, 9, 2, 18, 18),
datetime(1997, 9, 3, 6, 6)])
def testHourlyByHourAndSecond(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byhour=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0, 6),
datetime(1997, 9, 2, 18, 0, 18),
datetime(1997, 9, 3, 6, 0, 6)])
def testHourlyByMinuteAndSecond(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6, 6),
datetime(1997, 9, 2, 9, 6, 18),
datetime(1997, 9, 2, 9, 18, 6)])
def testHourlyByHourAndMinuteAndSecond(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byhour=(6,18),
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6, 6),
datetime(1997, 9, 2, 18, 6, 18),
datetime(1997, 9, 2, 18, 18, 6)])
def testHourlyBySetPos(self):
self.assertEqual(list(rrule(HOURLY,
count=3,
byminute=(15,45),
bysecond=(15,45),
bysetpos=(3,-3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 15, 45),
datetime(1997, 9, 2, 9, 45, 15),
datetime(1997, 9, 2, 10, 15, 45)])
def testMinutely(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 2, 9, 1),
datetime(1997, 9, 2, 9, 2)])
def testMinutelyInterval(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
interval=2,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 2, 9, 2),
datetime(1997, 9, 2, 9, 4)])
def testMinutelyIntervalLarge(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
interval=1501,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 3, 10, 1),
datetime(1997, 9, 4, 11, 2)])
def testMinutelyByMonth(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
bymonth=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0),
datetime(1998, 1, 1, 0, 1),
datetime(1998, 1, 1, 0, 2)])
def testMinutelyByMonthDay(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
bymonthday=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 3, 0, 0),
datetime(1997, 9, 3, 0, 1),
datetime(1997, 9, 3, 0, 2)])
def testMinutelyByMonthAndMonthDay(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
bymonth=(1,3),
bymonthday=(5,7),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 5, 0, 0),
datetime(1998, 1, 5, 0, 1),
datetime(1998, 1, 5, 0, 2)])
def testMinutelyByWeekDay(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 2, 9, 1),
datetime(1997, 9, 2, 9, 2)])
def testMinutelyByNWeekDay(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 2, 9, 1),
datetime(1997, 9, 2, 9, 2)])
def testMinutelyByMonthAndWeekDay(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
bymonth=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0),
datetime(1998, 1, 1, 0, 1),
datetime(1998, 1, 1, 0, 2)])
def testMinutelyByMonthAndNWeekDay(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
bymonth=(1,3),
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0),
datetime(1998, 1, 1, 0, 1),
datetime(1998, 1, 1, 0, 2)])
def testMinutelyByMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0),
datetime(1998, 1, 1, 0, 1),
datetime(1998, 1, 1, 0, 2)])
def testMinutelyByMonthAndMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
bymonth=(1,3),
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0),
datetime(1998, 1, 1, 0, 1),
datetime(1998, 1, 1, 0, 2)])
def testMinutelyByYearDay(self):
self.assertEqual(list(rrule(MINUTELY,
count=4,
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 0, 0),
datetime(1997, 12, 31, 0, 1),
datetime(1997, 12, 31, 0, 2),
datetime(1997, 12, 31, 0, 3)])
def testMinutelyByYearDayNeg(self):
self.assertEqual(list(rrule(MINUTELY,
count=4,
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 0, 0),
datetime(1997, 12, 31, 0, 1),
datetime(1997, 12, 31, 0, 2),
datetime(1997, 12, 31, 0, 3)])
def testMinutelyByMonthAndYearDay(self):
self.assertEqual(list(rrule(MINUTELY,
count=4,
bymonth=(4,7),
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 10, 0, 0),
datetime(1998, 4, 10, 0, 1),
datetime(1998, 4, 10, 0, 2),
datetime(1998, 4, 10, 0, 3)])
def testMinutelyByMonthAndYearDayNeg(self):
self.assertEqual(list(rrule(MINUTELY,
count=4,
bymonth=(4,7),
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 10, 0, 0),
datetime(1998, 4, 10, 0, 1),
datetime(1998, 4, 10, 0, 2),
datetime(1998, 4, 10, 0, 3)])
def testMinutelyByWeekNo(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byweekno=20,
dtstart=parse("19970902T090000"))),
[datetime(1998, 5, 11, 0, 0),
datetime(1998, 5, 11, 0, 1),
datetime(1998, 5, 11, 0, 2)])
def testMinutelyByWeekNoAndWeekDay(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byweekno=1,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 29, 0, 0),
datetime(1997, 12, 29, 0, 1),
datetime(1997, 12, 29, 0, 2)])
def testMinutelyByWeekNoAndWeekDayLarge(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byweekno=52,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 0, 0),
datetime(1997, 12, 28, 0, 1),
datetime(1997, 12, 28, 0, 2)])
def testMinutelyByWeekNoAndWeekDayLast(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byweekno=-1,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 0, 0),
datetime(1997, 12, 28, 0, 1),
datetime(1997, 12, 28, 0, 2)])
def testMinutelyByWeekNoAndWeekDay53(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byweekno=53,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1998, 12, 28, 0, 0),
datetime(1998, 12, 28, 0, 1),
datetime(1998, 12, 28, 0, 2)])
def testMinutelyByEaster(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byeaster=0,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 12, 0, 0),
datetime(1998, 4, 12, 0, 1),
datetime(1998, 4, 12, 0, 2)])
def testMinutelyByEasterPos(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byeaster=1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 13, 0, 0),
datetime(1998, 4, 13, 0, 1),
datetime(1998, 4, 13, 0, 2)])
def testMinutelyByEasterNeg(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byeaster=-1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 11, 0, 0),
datetime(1998, 4, 11, 0, 1),
datetime(1998, 4, 11, 0, 2)])
def testMinutelyByHour(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byhour=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0),
datetime(1997, 9, 2, 18, 1),
datetime(1997, 9, 2, 18, 2)])
def testMinutelyByMinute(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6),
datetime(1997, 9, 2, 9, 18),
datetime(1997, 9, 2, 10, 6)])
def testMinutelyBySecond(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 6),
datetime(1997, 9, 2, 9, 0, 18),
datetime(1997, 9, 2, 9, 1, 6)])
def testMinutelyByHourAndMinute(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byhour=(6,18),
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6),
datetime(1997, 9, 2, 18, 18),
datetime(1997, 9, 3, 6, 6)])
def testMinutelyByHourAndSecond(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byhour=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0, 6),
datetime(1997, 9, 2, 18, 0, 18),
datetime(1997, 9, 2, 18, 1, 6)])
def testMinutelyByMinuteAndSecond(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6, 6),
datetime(1997, 9, 2, 9, 6, 18),
datetime(1997, 9, 2, 9, 18, 6)])
def testMinutelyByHourAndMinuteAndSecond(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
byhour=(6,18),
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6, 6),
datetime(1997, 9, 2, 18, 6, 18),
datetime(1997, 9, 2, 18, 18, 6)])
def testMinutelyBySetPos(self):
self.assertEqual(list(rrule(MINUTELY,
count=3,
bysecond=(15,30,45),
bysetpos=(3,-3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 15),
datetime(1997, 9, 2, 9, 0, 45),
datetime(1997, 9, 2, 9, 1, 15)])
def testSecondly(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 0),
datetime(1997, 9, 2, 9, 0, 1),
datetime(1997, 9, 2, 9, 0, 2)])
def testSecondlyInterval(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
interval=2,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 0),
datetime(1997, 9, 2, 9, 0, 2),
datetime(1997, 9, 2, 9, 0, 4)])
def testSecondlyIntervalLarge(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
interval=90061,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 0),
datetime(1997, 9, 3, 10, 1, 1),
datetime(1997, 9, 4, 11, 2, 2)])
def testSecondlyByMonth(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
bymonth=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0, 0),
datetime(1998, 1, 1, 0, 0, 1),
datetime(1998, 1, 1, 0, 0, 2)])
def testSecondlyByMonthDay(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
bymonthday=(1,3),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 3, 0, 0, 0),
datetime(1997, 9, 3, 0, 0, 1),
datetime(1997, 9, 3, 0, 0, 2)])
def testSecondlyByMonthAndMonthDay(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
bymonth=(1,3),
bymonthday=(5,7),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 5, 0, 0, 0),
datetime(1998, 1, 5, 0, 0, 1),
datetime(1998, 1, 5, 0, 0, 2)])
def testSecondlyByWeekDay(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 0),
datetime(1997, 9, 2, 9, 0, 1),
datetime(1997, 9, 2, 9, 0, 2)])
def testSecondlyByNWeekDay(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 0),
datetime(1997, 9, 2, 9, 0, 1),
datetime(1997, 9, 2, 9, 0, 2)])
def testSecondlyByMonthAndWeekDay(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
bymonth=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0, 0),
datetime(1998, 1, 1, 0, 0, 1),
datetime(1998, 1, 1, 0, 0, 2)])
def testSecondlyByMonthAndNWeekDay(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
bymonth=(1,3),
byweekday=(TU(1),TH(-1)),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0, 0),
datetime(1998, 1, 1, 0, 0, 1),
datetime(1998, 1, 1, 0, 0, 2)])
def testSecondlyByMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0, 0),
datetime(1998, 1, 1, 0, 0, 1),
datetime(1998, 1, 1, 0, 0, 2)])
def testSecondlyByMonthAndMonthDayAndWeekDay(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
bymonth=(1,3),
bymonthday=(1,3),
byweekday=(TU,TH),
dtstart=parse("19970902T090000"))),
[datetime(1998, 1, 1, 0, 0, 0),
datetime(1998, 1, 1, 0, 0, 1),
datetime(1998, 1, 1, 0, 0, 2)])
def testSecondlyByYearDay(self):
self.assertEqual(list(rrule(SECONDLY,
count=4,
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 0, 0, 0),
datetime(1997, 12, 31, 0, 0, 1),
datetime(1997, 12, 31, 0, 0, 2),
datetime(1997, 12, 31, 0, 0, 3)])
def testSecondlyByYearDayNeg(self):
self.assertEqual(list(rrule(SECONDLY,
count=4,
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 31, 0, 0, 0),
datetime(1997, 12, 31, 0, 0, 1),
datetime(1997, 12, 31, 0, 0, 2),
datetime(1997, 12, 31, 0, 0, 3)])
def testSecondlyByMonthAndYearDay(self):
self.assertEqual(list(rrule(SECONDLY,
count=4,
bymonth=(4,7),
byyearday=(1,100,200,365),
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 10, 0, 0, 0),
datetime(1998, 4, 10, 0, 0, 1),
datetime(1998, 4, 10, 0, 0, 2),
datetime(1998, 4, 10, 0, 0, 3)])
def testSecondlyByMonthAndYearDayNeg(self):
self.assertEqual(list(rrule(SECONDLY,
count=4,
bymonth=(4,7),
byyearday=(-365,-266,-166,-1),
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 10, 0, 0, 0),
datetime(1998, 4, 10, 0, 0, 1),
datetime(1998, 4, 10, 0, 0, 2),
datetime(1998, 4, 10, 0, 0, 3)])
def testSecondlyByWeekNo(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byweekno=20,
dtstart=parse("19970902T090000"))),
[datetime(1998, 5, 11, 0, 0, 0),
datetime(1998, 5, 11, 0, 0, 1),
datetime(1998, 5, 11, 0, 0, 2)])
def testSecondlyByWeekNoAndWeekDay(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byweekno=1,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 29, 0, 0, 0),
datetime(1997, 12, 29, 0, 0, 1),
datetime(1997, 12, 29, 0, 0, 2)])
def testSecondlyByWeekNoAndWeekDayLarge(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byweekno=52,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 0, 0, 0),
datetime(1997, 12, 28, 0, 0, 1),
datetime(1997, 12, 28, 0, 0, 2)])
def testSecondlyByWeekNoAndWeekDayLast(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byweekno=-1,
byweekday=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 12, 28, 0, 0, 0),
datetime(1997, 12, 28, 0, 0, 1),
datetime(1997, 12, 28, 0, 0, 2)])
def testSecondlyByWeekNoAndWeekDay53(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byweekno=53,
byweekday=MO,
dtstart=parse("19970902T090000"))),
[datetime(1998, 12, 28, 0, 0, 0),
datetime(1998, 12, 28, 0, 0, 1),
datetime(1998, 12, 28, 0, 0, 2)])
def testSecondlyByEaster(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byeaster=0,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 12, 0, 0, 0),
datetime(1998, 4, 12, 0, 0, 1),
datetime(1998, 4, 12, 0, 0, 2)])
def testSecondlyByEasterPos(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byeaster=1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 13, 0, 0, 0),
datetime(1998, 4, 13, 0, 0, 1),
datetime(1998, 4, 13, 0, 0, 2)])
def testSecondlyByEasterNeg(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byeaster=-1,
dtstart=parse("19970902T090000"))),
[datetime(1998, 4, 11, 0, 0, 0),
datetime(1998, 4, 11, 0, 0, 1),
datetime(1998, 4, 11, 0, 0, 2)])
def testSecondlyByHour(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byhour=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0, 0),
datetime(1997, 9, 2, 18, 0, 1),
datetime(1997, 9, 2, 18, 0, 2)])
def testSecondlyByMinute(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6, 0),
datetime(1997, 9, 2, 9, 6, 1),
datetime(1997, 9, 2, 9, 6, 2)])
def testSecondlyBySecond(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0, 6),
datetime(1997, 9, 2, 9, 0, 18),
datetime(1997, 9, 2, 9, 1, 6)])
def testSecondlyByHourAndMinute(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byhour=(6,18),
byminute=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6, 0),
datetime(1997, 9, 2, 18, 6, 1),
datetime(1997, 9, 2, 18, 6, 2)])
def testSecondlyByHourAndSecond(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byhour=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 0, 6),
datetime(1997, 9, 2, 18, 0, 18),
datetime(1997, 9, 2, 18, 1, 6)])
def testSecondlyByMinuteAndSecond(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 6, 6),
datetime(1997, 9, 2, 9, 6, 18),
datetime(1997, 9, 2, 9, 18, 6)])
def testSecondlyByHourAndMinuteAndSecond(self):
self.assertEqual(list(rrule(SECONDLY,
count=3,
byhour=(6,18),
byminute=(6,18),
bysecond=(6,18),
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 18, 6, 6),
datetime(1997, 9, 2, 18, 6, 18),
datetime(1997, 9, 2, 18, 18, 6)])
def testUntilNotMatching(self):
self.assertEqual(list(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000"),
until=parse("19970905T080000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 3, 9, 0),
datetime(1997, 9, 4, 9, 0)])
def testUntilMatching(self):
self.assertEqual(list(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000"),
until=parse("19970904T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 3, 9, 0),
datetime(1997, 9, 4, 9, 0)])
def testUntilSingle(self):
self.assertEqual(list(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000"),
until=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0)])
def testUntilEmpty(self):
self.assertEqual(list(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000"),
until=parse("19970901T090000"))),
[])
def testUntilWithDate(self):
self.assertEqual(list(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000"),
until=date(1997, 9, 5))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 3, 9, 0),
datetime(1997, 9, 4, 9, 0)])
def testWkStIntervalMO(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
interval=2,
byweekday=(TU,SU),
wkst=MO,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 7, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testWkStIntervalSU(self):
self.assertEqual(list(rrule(WEEKLY,
count=3,
interval=2,
byweekday=(TU,SU),
wkst=SU,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 14, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testDTStartIsDate(self):
self.assertEqual(list(rrule(DAILY,
count=3,
dtstart=date(1997, 9, 2))),
[datetime(1997, 9, 2, 0, 0),
datetime(1997, 9, 3, 0, 0),
datetime(1997, 9, 4, 0, 0)])
def testDTStartWithMicroseconds(self):
self.assertEqual(list(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000.5"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 3, 9, 0),
datetime(1997, 9, 4, 9, 0)])
def testMaxYear(self):
self.assertEqual(list(rrule(YEARLY,
count=3,
bymonth=2,
bymonthday=31,
dtstart=parse("99970902T090000"))),
[])
def testGetItem(self):
self.assertEqual(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000"))[0],
datetime(1997, 9, 2, 9, 0))
def testGetItemNeg(self):
self.assertEqual(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000"))[-1],
datetime(1997, 9, 4, 9, 0))
def testGetItemSlice(self):
self.assertEqual(rrule(DAILY,
#count=3,
dtstart=parse("19970902T090000"))[1:2],
[datetime(1997, 9, 3, 9, 0)])
def testGetItemSliceEmpty(self):
self.assertEqual(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000"))[:],
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 3, 9, 0),
datetime(1997, 9, 4, 9, 0)])
def testGetItemSliceStep(self):
self.assertEqual(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000"))[::-2],
[datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 2, 9, 0)])
def testCount(self):
self.assertEqual(rrule(DAILY,
count=3,
dtstart=parse("19970902T090000")).count(),
3)
def testContains(self):
rr = rrule(DAILY, count=3, dtstart=parse("19970902T090000"))
self.assertEqual(datetime(1997, 9, 3, 9, 0) in rr, True)
def testContainsNot(self):
rr = rrule(DAILY, count=3, dtstart=parse("19970902T090000"))
self.assertEqual(datetime(1997, 9, 3, 9, 0) not in rr, False)
def testBefore(self):
self.assertEqual(rrule(DAILY,
#count=5,
dtstart=parse("19970902T090000"))
.before(parse("19970905T090000")),
datetime(1997, 9, 4, 9, 0))
def testBeforeInc(self):
self.assertEqual(rrule(DAILY,
#count=5,
dtstart=parse("19970902T090000"))
.before(parse("19970905T090000"), inc=True),
datetime(1997, 9, 5, 9, 0))
def testAfter(self):
self.assertEqual(rrule(DAILY,
#count=5,
dtstart=parse("19970902T090000"))
.after(parse("19970904T090000")),
datetime(1997, 9, 5, 9, 0))
def testAfterInc(self):
self.assertEqual(rrule(DAILY,
#count=5,
dtstart=parse("19970902T090000"))
.after(parse("19970904T090000"), inc=True),
datetime(1997, 9, 4, 9, 0))
def testBetween(self):
self.assertEqual(rrule(DAILY,
#count=5,
dtstart=parse("19970902T090000"))
.between(parse("19970902T090000"),
parse("19970906T090000")),
[datetime(1997, 9, 3, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 5, 9, 0)])
def testBetweenInc(self):
self.assertEqual(rrule(DAILY,
#count=5,
dtstart=parse("19970902T090000"))
.between(parse("19970902T090000"),
parse("19970906T090000"), inc=True),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 3, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 5, 9, 0),
datetime(1997, 9, 6, 9, 0)])
def testCachePre(self):
rr = rrule(DAILY, count=15, cache=True,
dtstart=parse("19970902T090000"))
self.assertEqual(list(rr),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 3, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 5, 9, 0),
datetime(1997, 9, 6, 9, 0),
datetime(1997, 9, 7, 9, 0),
datetime(1997, 9, 8, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 10, 9, 0),
datetime(1997, 9, 11, 9, 0),
datetime(1997, 9, 12, 9, 0),
datetime(1997, 9, 13, 9, 0),
datetime(1997, 9, 14, 9, 0),
datetime(1997, 9, 15, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testCachePost(self):
rr = rrule(DAILY, count=15, cache=True,
dtstart=parse("19970902T090000"))
for x in rr: pass
self.assertEqual(list(rr),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 3, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 5, 9, 0),
datetime(1997, 9, 6, 9, 0),
datetime(1997, 9, 7, 9, 0),
datetime(1997, 9, 8, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 10, 9, 0),
datetime(1997, 9, 11, 9, 0),
datetime(1997, 9, 12, 9, 0),
datetime(1997, 9, 13, 9, 0),
datetime(1997, 9, 14, 9, 0),
datetime(1997, 9, 15, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testCachePostInternal(self):
rr = rrule(DAILY, count=15, cache=True,
dtstart=parse("19970902T090000"))
for x in rr: pass
self.assertEqual(rr._cache,
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 3, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 5, 9, 0),
datetime(1997, 9, 6, 9, 0),
datetime(1997, 9, 7, 9, 0),
datetime(1997, 9, 8, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 10, 9, 0),
datetime(1997, 9, 11, 9, 0),
datetime(1997, 9, 12, 9, 0),
datetime(1997, 9, 13, 9, 0),
datetime(1997, 9, 14, 9, 0),
datetime(1997, 9, 15, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testCachePreContains(self):
rr = rrule(DAILY, count=3, cache=True,
dtstart=parse("19970902T090000"))
self.assertEqual(datetime(1997, 9, 3, 9, 0) in rr, True)
def testCachePostContains(self):
rr = rrule(DAILY, count=3, cache=True,
dtstart=parse("19970902T090000"))
for x in rr: pass
self.assertEqual(datetime(1997, 9, 3, 9, 0) in rr, True)
def testSet(self):
set = rruleset()
set.rrule(rrule(YEARLY, count=2, byweekday=TU,
dtstart=parse("19970902T090000")))
set.rrule(rrule(YEARLY, count=1, byweekday=TH,
dtstart=parse("19970902T090000")))
self.assertEqual(list(set),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testSetDate(self):
set = rruleset()
set.rrule(rrule(YEARLY, count=1, byweekday=TU,
dtstart=parse("19970902T090000")))
set.rdate(datetime(1997, 9, 4, 9))
set.rdate(datetime(1997, 9, 9, 9))
self.assertEqual(list(set),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testSetExRule(self):
set = rruleset()
set.rrule(rrule(YEARLY, count=6, byweekday=(TU,TH),
dtstart=parse("19970902T090000")))
set.exrule(rrule(YEARLY, count=3, byweekday=TH,
dtstart=parse("19970902T090000")))
self.assertEqual(list(set),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testSetExDate(self):
set = rruleset()
set.rrule(rrule(YEARLY, count=6, byweekday=(TU,TH),
dtstart=parse("19970902T090000")))
set.exdate(datetime(1997, 9, 4, 9))
set.exdate(datetime(1997, 9, 11, 9))
set.exdate(datetime(1997, 9, 18, 9))
self.assertEqual(list(set),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testSetExDateRevOrder(self):
set = rruleset()
set.rrule(rrule(MONTHLY, count=5, bymonthday=10,
dtstart=parse("20040101T090000")))
set.exdate(datetime(2004, 4, 10, 9, 0))
set.exdate(datetime(2004, 2, 10, 9, 0))
self.assertEqual(list(set),
[datetime(2004, 1, 10, 9, 0),
datetime(2004, 3, 10, 9, 0),
datetime(2004, 5, 10, 9, 0)])
def testSetDateAndExDate(self):
set = rruleset()
set.rdate(datetime(1997, 9, 2, 9))
set.rdate(datetime(1997, 9, 4, 9))
set.rdate(datetime(1997, 9, 9, 9))
set.rdate(datetime(1997, 9, 11, 9))
set.rdate(datetime(1997, 9, 16, 9))
set.rdate(datetime(1997, 9, 18, 9))
set.exdate(datetime(1997, 9, 4, 9))
set.exdate(datetime(1997, 9, 11, 9))
set.exdate(datetime(1997, 9, 18, 9))
self.assertEqual(list(set),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testSetDateAndExRule(self):
set = rruleset()
set.rdate(datetime(1997, 9, 2, 9))
set.rdate(datetime(1997, 9, 4, 9))
set.rdate(datetime(1997, 9, 9, 9))
set.rdate(datetime(1997, 9, 11, 9))
set.rdate(datetime(1997, 9, 16, 9))
set.rdate(datetime(1997, 9, 18, 9))
set.exrule(rrule(YEARLY, count=3, byweekday=TH,
dtstart=parse("19970902T090000")))
self.assertEqual(list(set),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testSetCount(self):
set = rruleset()
set.rrule(rrule(YEARLY, count=6, byweekday=(TU,TH),
dtstart=parse("19970902T090000")))
set.exrule(rrule(YEARLY, count=3, byweekday=TH,
dtstart=parse("19970902T090000")))
self.assertEqual(set.count(), 3)
def testSetCachePre(self):
set = rruleset()
set.rrule(rrule(YEARLY, count=2, byweekday=TU,
dtstart=parse("19970902T090000")))
set.rrule(rrule(YEARLY, count=1, byweekday=TH,
dtstart=parse("19970902T090000")))
self.assertEqual(list(set),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testSetCachePost(self):
set = rruleset(cache=True)
set.rrule(rrule(YEARLY, count=2, byweekday=TU,
dtstart=parse("19970902T090000")))
set.rrule(rrule(YEARLY, count=1, byweekday=TH,
dtstart=parse("19970902T090000")))
for x in set: pass
self.assertEqual(list(set),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testSetCachePostInternal(self):
set = rruleset(cache=True)
set.rrule(rrule(YEARLY, count=2, byweekday=TU,
dtstart=parse("19970902T090000")))
set.rrule(rrule(YEARLY, count=1, byweekday=TH,
dtstart=parse("19970902T090000")))
for x in set: pass
self.assertEqual(list(set._cache),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testStr(self):
self.assertEqual(list(rrulestr(
"DTSTART:19970902T090000\n"
"RRULE:FREQ=YEARLY;COUNT=3\n"
)),
[datetime(1997, 9, 2, 9, 0),
datetime(1998, 9, 2, 9, 0),
datetime(1999, 9, 2, 9, 0)])
def testStrType(self):
self.assertEqual(isinstance(rrulestr(
"DTSTART:19970902T090000\n"
"RRULE:FREQ=YEARLY;COUNT=3\n"
), rrule), True)
def testStrForceSetType(self):
self.assertEqual(isinstance(rrulestr(
"DTSTART:19970902T090000\n"
"RRULE:FREQ=YEARLY;COUNT=3\n"
, forceset=True), rruleset), True)
def testStrSetType(self):
self.assertEqual(isinstance(rrulestr(
"DTSTART:19970902T090000\n"
"RRULE:FREQ=YEARLY;COUNT=2;BYDAY=TU\n"
"RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TH\n"
), rruleset), True)
def testStrCase(self):
self.assertEqual(list(rrulestr(
"dtstart:19970902T090000\n"
"rrule:freq=yearly;count=3\n"
)),
[datetime(1997, 9, 2, 9, 0),
datetime(1998, 9, 2, 9, 0),
datetime(1999, 9, 2, 9, 0)])
def testStrSpaces(self):
self.assertEqual(list(rrulestr(
" DTSTART:19970902T090000 "
" RRULE:FREQ=YEARLY;COUNT=3 "
)),
[datetime(1997, 9, 2, 9, 0),
datetime(1998, 9, 2, 9, 0),
datetime(1999, 9, 2, 9, 0)])
def testStrExperimentalProp(self):
self.assertEqual(list(rrulestr(
"DTSTART:19970902T090000\n"
"X-MEN:Wolverine\n"
"RRULE:FREQ=YEARLY;COUNT=3\n"
)),
[datetime(1997, 9, 2, 9, 0),
datetime(1998, 9, 2, 9, 0),
datetime(1999, 9, 2, 9, 0)])
def testStrSpacesAndLines(self):
self.assertEqual(list(rrulestr(
" DTSTART:19970902T090000 \n"
" \n"
" RRULE:FREQ=YEARLY;COUNT=3 \n"
)),
[datetime(1997, 9, 2, 9, 0),
datetime(1998, 9, 2, 9, 0),
datetime(1999, 9, 2, 9, 0)])
def testStrNoDTStart(self):
self.assertEqual(list(rrulestr(
"RRULE:FREQ=YEARLY;COUNT=3\n"
, dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1998, 9, 2, 9, 0),
datetime(1999, 9, 2, 9, 0)])
def testStrValueOnly(self):
self.assertEqual(list(rrulestr(
"FREQ=YEARLY;COUNT=3\n"
, dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1998, 9, 2, 9, 0),
datetime(1999, 9, 2, 9, 0)])
def testStrUnfold(self):
self.assertEqual(list(rrulestr(
"FREQ=YEA\n RLY;COUNT=3\n", unfold=True,
dtstart=parse("19970902T090000"))),
[datetime(1997, 9, 2, 9, 0),
datetime(1998, 9, 2, 9, 0),
datetime(1999, 9, 2, 9, 0)])
def testStrSet(self):
self.assertEqual(list(rrulestr(
"DTSTART:19970902T090000\n"
"RRULE:FREQ=YEARLY;COUNT=2;BYDAY=TU\n"
"RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TH\n"
)),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testStrSetDate(self):
self.assertEqual(list(rrulestr(
"DTSTART:19970902T090000\n"
"RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TU\n"
"RDATE:19970904T090000\n"
"RDATE:19970909T090000\n"
)),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 4, 9, 0),
datetime(1997, 9, 9, 9, 0)])
def testStrSetExRule(self):
self.assertEqual(list(rrulestr(
"DTSTART:19970902T090000\n"
"RRULE:FREQ=YEARLY;COUNT=6;BYDAY=TU,TH\n"
"EXRULE:FREQ=YEARLY;COUNT=3;BYDAY=TH\n"
)),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testStrSetExDate(self):
self.assertEqual(list(rrulestr(
"DTSTART:19970902T090000\n"
"RRULE:FREQ=YEARLY;COUNT=6;BYDAY=TU,TH\n"
"EXDATE:19970904T090000\n"
"EXDATE:19970911T090000\n"
"EXDATE:19970918T090000\n"
)),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testStrSetDateAndExDate(self):
self.assertEqual(list(rrulestr(
"DTSTART:19970902T090000\n"
"RDATE:19970902T090000\n"
"RDATE:19970904T090000\n"
"RDATE:19970909T090000\n"
"RDATE:19970911T090000\n"
"RDATE:19970916T090000\n"
"RDATE:19970918T090000\n"
"EXDATE:19970904T090000\n"
"EXDATE:19970911T090000\n"
"EXDATE:19970918T090000\n"
)),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testStrSetDateAndExRule(self):
self.assertEqual(list(rrulestr(
"DTSTART:19970902T090000\n"
"RDATE:19970902T090000\n"
"RDATE:19970904T090000\n"
"RDATE:19970909T090000\n"
"RDATE:19970911T090000\n"
"RDATE:19970916T090000\n"
"RDATE:19970918T090000\n"
"EXRULE:FREQ=YEARLY;COUNT=3;BYDAY=TH\n"
)),
[datetime(1997, 9, 2, 9, 0),
datetime(1997, 9, 9, 9, 0),
datetime(1997, 9, 16, 9, 0)])
def testStrKeywords(self):
self.assertEqual(list(rrulestr(
"DTSTART:19970902T090000\n"
"RRULE:FREQ=YEARLY;COUNT=3;INTERVAL=3;"
"BYMONTH=3;BYWEEKDAY=TH;BYMONTHDAY=3;"
"BYHOUR=3;BYMINUTE=3;BYSECOND=3\n"
)),
[datetime(2033, 3, 3, 3, 3, 3),
datetime(2039, 3, 3, 3, 3, 3),
datetime(2072, 3, 3, 3, 3, 3)])
def testStrNWeekDay(self):
self.assertEqual(list(rrulestr(
"DTSTART:19970902T090000\n"
"RRULE:FREQ=YEARLY;COUNT=3;BYDAY=1TU,-1TH\n"
)),
[datetime(1997, 12, 25, 9, 0),
datetime(1998, 1, 6, 9, 0),
datetime(1998, 12, 31, 9, 0)])
def testBadBySetPos(self):
self.assertRaises(ValueError,
rrule, MONTHLY,
count=1,
bysetpos=0,
dtstart=parse("19970902T090000"))
def testBadBySetPosMany(self):
self.assertRaises(ValueError,
rrule, MONTHLY,
count=1,
bysetpos=(-1,0,1),
dtstart=parse("19970902T090000"))
class ParserTest(unittest.TestCase):
def setUp(self):
self.tzinfos = {"BRST": -10800}
self.brsttz = tzoffset("BRST", -10800)
self.default = datetime(2003, 9, 25)
def testDateCommandFormat(self):
self.assertEqual(parse("Thu Sep 25 10:36:28 BRST 2003",
tzinfos=self.tzinfos),
datetime(2003, 9, 25, 10, 36, 28,
tzinfo=self.brsttz))
def testDateCommandFormatUnicode(self):
self.assertEqual(parse(u"Thu Sep 25 10:36:28 BRST 2003",
tzinfos=self.tzinfos),
datetime(2003, 9, 25, 10, 36, 28,
tzinfo=self.brsttz))
def testDateCommandFormatReversed(self):
self.assertEqual(parse("2003 10:36:28 BRST 25 Sep Thu",
tzinfos=self.tzinfos),
datetime(2003, 9, 25, 10, 36, 28,
tzinfo=self.brsttz))
def testDateCommandFormatIgnoreTz(self):
self.assertEqual(parse("Thu Sep 25 10:36:28 BRST 2003",
ignoretz=True),
datetime(2003, 9, 25, 10, 36, 28))
def testDateCommandFormatStrip1(self):
self.assertEqual(parse("Thu Sep 25 10:36:28 2003"),
datetime(2003, 9, 25, 10, 36, 28))
def testDateCommandFormatStrip2(self):
self.assertEqual(parse("Thu Sep 25 10:36:28", default=self.default),
datetime(2003, 9, 25, 10, 36, 28))
def testDateCommandFormatStrip3(self):
self.assertEqual(parse("Thu Sep 10:36:28", default=self.default),
datetime(2003, 9, 25, 10, 36, 28))
def testDateCommandFormatStrip4(self):
self.assertEqual(parse("Thu 10:36:28", default=self.default),
datetime(2003, 9, 25, 10, 36, 28))
def testDateCommandFormatStrip5(self):
self.assertEqual(parse("Sep 10:36:28", default=self.default),
datetime(2003, 9, 25, 10, 36, 28))
def testDateCommandFormatStrip6(self):
self.assertEqual(parse("10:36:28", default=self.default),
datetime(2003, 9, 25, 10, 36, 28))
def testDateCommandFormatStrip7(self):
self.assertEqual(parse("10:36", default=self.default),
datetime(2003, 9, 25, 10, 36))
def testDateCommandFormatStrip8(self):
self.assertEqual(parse("Thu Sep 25 2003"),
datetime(2003, 9, 25))
def testDateCommandFormatStrip9(self):
self.assertEqual(parse("Sep 25 2003"),
datetime(2003, 9, 25))
def testDateCommandFormatStrip9(self):
self.assertEqual(parse("Sep 2003", default=self.default),
datetime(2003, 9, 25))
def testDateCommandFormatStrip10(self):
self.assertEqual(parse("Sep", default=self.default),
datetime(2003, 9, 25))
def testDateCommandFormatStrip11(self):
self.assertEqual(parse("2003", default=self.default),
datetime(2003, 9, 25))
def testDateRCommandFormat(self):
self.assertEqual(parse("Thu, 25 Sep 2003 10:49:41 -0300"),
datetime(2003, 9, 25, 10, 49, 41,
tzinfo=self.brsttz))
def testISOFormat(self):
self.assertEqual(parse("2003-09-25T10:49:41.5-03:00"),
datetime(2003, 9, 25, 10, 49, 41, 500000,
tzinfo=self.brsttz))
def testISOFormatStrip1(self):
self.assertEqual(parse("2003-09-25T10:49:41-03:00"),
datetime(2003, 9, 25, 10, 49, 41,