def testGetPointsRecurUntil(self):
     start = datetime(2007, 12, 22, 9, 0, 0, 0, LOCAL)
     end = datetime(2007, 12, 22, 11, 0, 0, 0, LOCAL)
     event = eventcalendar.Event(
         'uid',
         start,
         end,
         'content',
         rrules=[
             "FREQ=DAILY;UNTIL=20071224T073000Z;WKST=MO",
         ])
     set = eventcalendar.EventSet('uid')
     set.addEvent(event)
     p = set.getPoints(start, end - start)
     self.assertEquals(p[0].dt, start)
     self.assertEquals(p[0].which, 'start')
     self.assertEquals(p[1].which, 'end')
     p = set.getPoints(start, end - start + timedelta(days=4))
     self.assertEquals(len(p), 4)
     self.assertEquals(p[0].dt, start)
     self.assertEquals(p[0].which, 'start')
     self.assertEquals(p[3].dt, end + timedelta(days=1))
     self.assertEquals(p[3].which, 'end')
     p = set.getPoints(start + timedelta(hours=1),
                       end - start + timedelta(hours=22))
     self.assertEquals(len(p), 4)
     self.assertEquals(p[0].dt, start + timedelta(hours=1))
     self.assertEquals(p[0].which, 'start')
     self.assertEquals(p[1].dt, start + timedelta(hours=2))
     self.assertEquals(p[1].which, 'end')
     self.assertEquals(p[3].dt,
                       end + timedelta(days=1) - timedelta(hours=1))
     self.assertEquals(p[3].which, 'end')
     p = set.getPoints(start + timedelta(days=3), end - start)
     self.assertEquals(len(p), 0)
 def testExWithRecurrence(self):
     """
     Exception to a recurrence rule.
     """
     start = datetime(2007, 12, 22, 9, 0, 0, 0, LOCAL)
     end = datetime(2007, 12, 22, 11, 0, 0, 0, LOCAL)
     uid = 'uid'
     content = 'content'
     rrules = [
         "FREQ=DAILY;WKST=MO",
     ]
     exdate = datetime(2007, 12, 23, 9, 0, 0, 0, LOCAL)
     exdates = [exdate]
     event = eventcalendar.Event(uid,
                                 start,
                                 end,
                                 content,
                                 rrules=rrules,
                                 exdates=exdates)
     set = eventcalendar.EventSet(uid)
     set.addEvent(event)
     p = set.getPoints(start, end - start)
     self.assertEquals(p[0].dt, start)
     self.assertEquals(p[0].which, 'start')
     self.assertEquals(p[1].which, 'end')
     p = set.getPoints(exdate, timedelta(days=1))
     self.failIf(p)
    def testRecurrenceOverMidnight(self):
        """
        Test weekly recurrence rules that starts on one day and spawns to
        the day after, even though they were not planned for the next day.
        """
        def yesterdayDayOfTheWeek(now):
            yesterday = now - timedelta(days=1)
            day = calendar.weekday(yesterday.year, yesterday.month,
                                   yesterday.day)
            return _dayOfTheWeek[day]

        now = datetime.now().replace(microsecond=0)
        start = now - timedelta(days=1) - timedelta(weeks=1)
        end = now + timedelta(hours=1) - timedelta(weeks=1)
        rrules = [
            "FREQ=WEEKLY;BYDAY=" + yesterdayDayOfTheWeek(now) + ";WKST=MO",
        ]
        uid = 'uid'
        content = 'content'
        event = eventcalendar.Event(uid, start, end, content, rrules=rrules)
        eventSet = eventcalendar.EventSet(uid)
        eventSet.addEvent(event)
        p = eventSet.getPoints(event.start + timedelta(weeks=1),
                               event.end - event.start)
        self.assertEquals(p[0].dt, event.start + timedelta(weeks=1))
        self.assertEquals(p[0].which, 'start')
        self.assertEquals(p[1].dt, event.end + timedelta(weeks=1))
        self.assertEquals(p[1].which, 'end')
 def testGetPoints(self):
     start = datetime(2007, 12, 22, 9, 0, 0, 0, LOCAL)
     end = datetime(2007, 12, 22, 11, 0, 0, 0, LOCAL)
     eventSet1 = eventcalendar.EventSet('uid1')
     eventSet2 = eventcalendar.EventSet('uid2')
     event1 = eventcalendar.Event('uid1', start, end, 'content')
     eventSet1.addEvent(event1)
     event2 = eventcalendar.Event('uid2', start, end, 'content')
     eventSet2.addEvent(event2)
     rid = self._events[0].get('RECURRENCE-ID')
     self.failUnless(rid)
     riddatetime = parser.parse(str(rid))
     self.failUnless(str(rid).endswith('Z'))
     start = self._events[1].decoded('dtstart')
     self.failUnless(start)
     if start.tzinfo is None:
         tzinfo = tz.gettz(self._events[1]['dtstart'].params['TZID'])
         start = datetime(start.year, start.month, start.day, start.hour,
                          start.minute, start.second, start.microsecond,
                          tzinfo)
     rrulestr = str(self._events[1].get('RRULE'))
     self.failUnless(rrulestr)
     r = rrule.rrulestr(rrulestr, dtstart=start)
     self.failUnless(riddatetime in r)
 def testGetPointSingle(self):
     start = datetime(2007, 12, 22, 9, 0, 0, 0, LOCAL)
     end = datetime(2007, 12, 22, 11, 0, 0, 0, LOCAL)
     uid = 'uid'
     content = 'content'
     event = eventcalendar.Event(uid, start, end, content)
     set = eventcalendar.EventSet(uid)
     set.addEvent(event)
     p = set.getPoints(start, end - start)
     self.assertEquals(p[0].dt, start)
     self.assertEquals(p[1].dt, end)
     p = set.getPoints(start - timedelta(hours=1), timedelta(hours=3))
     self.assertEquals(p[0].dt, start)
     self.assertEquals(p[1].dt, end)
     p = set.getPoints(start + timedelta(minutes=30), timedelta(minutes=60))
     self.assertEquals(p[0].dt, start + timedelta(minutes=30))
     self.assertEquals(p[1].dt, end - timedelta(minutes=30))
 def testGetPointsRecur(self):
     start = datetime(2007, 12, 22, 9, 0, 0, 0, LOCAL)
     end = datetime(2007, 12, 22, 11, 0, 0, 0, LOCAL)
     uid = 'uid'
     content = 'content'
     rrules = [
         "FREQ=DAILY;WKST=MO",
     ]
     event = eventcalendar.Event(uid, start, end, content, rrules=rrules)
     set = eventcalendar.EventSet(uid)
     set.addEvent(event)
     p = set.getPoints(start, end - start)
     self.assertEquals(p[0].dt, start)
     self.assertEquals(p[0].which, 'start')
     self.assertEquals(p[1].which, 'end')
     p = set.getPoints(start + timedelta(days=2), end - start)
     self.assertEquals(p[0].dt, start + timedelta(days=2))
     self.assertEquals(p[0].which, 'start')
     self.assertEquals(p[1].which, 'end')
     p = set.getPoints(end, timedelta(days=1))
     self.assertEquals(len(p), 2)
     self.assertNotEquals(p[0].dt, end)
 def testExAsStartDateWithRecurrence(self):
     """
     Exception to a recurrence rule.
     """
     start = datetime(2007, 12, 22, 9, 0, 0, 0, LOCAL)
     end = datetime(2007, 12, 22, 11, 0, 0, 0, LOCAL)
     uid = 'uid'
     content = 'content'
     rrules = [
         "FREQ=DAILY;WKST=MO",
     ]
     exdate = start
     exdates = [exdate]
     event = eventcalendar.Event(uid,
                                 start,
                                 end,
                                 content,
                                 rrules=rrules,
                                 exdates=exdates)
     set = eventcalendar.EventSet(uid)
     set.addEvent(event)
     p = set.getPoints(start, end - start)
     self.failIf(p)