Beispiel #1
0
    def test_compute_next_time(self):
        pattern = ("BEGIN:VEVENT\n"
                   "RRULE:FREQ=WEEKLY;INTERVAL=1;BYHOUR=17;BYMINUTE=1\n"
                   "END:VEVENT")
        dtstart = datetime(2016, 2, 20, 17, 0, 0)
        time_obj = calendar_time.ICal(dtstart, pattern)
        now = datetime(2016, 2, 20, 15, 11, 0)
        time1 = time_obj.compute_next_time(now)
        time2 = datetime(2016, 2, 20, 17, 1, 0)
        self.assertEqual(time2, time1)
        now = datetime(2016, 3, 20, 15, 11, 0)
        time1 = time_obj.compute_next_time(now)
        time2 = datetime(2016, 3, 26, 17, 1, 0)
        self.assertEqual(time2, time1)

        pattern = ("BEGIN:VEVENT\n"
                   "RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR;BYHOUR=10;BYMINUTE=0\n"
                   "RRULE:FREQ=WEEKLY;BYDAY=TU,TH,SA;BYHOUR=20;BYMINUTE=0\n"
                   "END:VEVENT")
        dtstart = datetime(2016, 2, 20, 17, 0, 0)
        time_obj = calendar_time.ICal(dtstart, pattern)
        now = datetime(2016, 7, 31, 15, 11, 0)
        time1 = time_obj.compute_next_time(now)
        time2 = datetime(2016, 8, 1, 10, 0, 0)
        self.assertEqual(time2, time1)
        time1 = time_obj.compute_next_time(time2)
        time2 = datetime(2016, 8, 2, 20, 0, 0)
        self.assertEqual(time2, time1)
        time1 = time_obj.compute_next_time(time2)
        time2 = datetime(2016, 8, 3, 10, 0, 0)
        self.assertEqual(time2, time1)
Beispiel #2
0
    def test_get_min_interval(self):
        pattern = ("BEGIN:VEVENT\n"
                   "RRULE:FREQ=WEEKLY;INTERVAL=1;BYHOUR=17;BYMINUTE=1\n"
                   "END:VEVENT")
        dtstart = datetime(2016, 2, 20, 17, 0, 0)
        time_obj = calendar_time.ICal(dtstart, pattern)
        self.assertEqual(604800, time_obj.get_min_interval())

        pattern = ("BEGIN:VEVENT\n" "RRULE:FREQ=WEEKLY;COUNT=1\n" "END:VEVENT")
        dtstart = datetime(2016, 2, 20, 17, 0, 0)
        time_obj = calendar_time.ICal(dtstart, pattern)
        self.assertIsNone(time_obj.get_min_interval())
Beispiel #3
0
 def test_get_min_interval_when_interval_is_bigger_than_default_rate(self):
     pattern = ("BEGIN:VEVENT\n"
                "RRULE:FREQ=MINUTELY;INTERVAL=5;\n"
                "END:VEVENT")
     dtstart = datetime(2016, 2, 20, 17, 0, 0)
     time_obj = calendar_time.ICal(dtstart, pattern)
     self.assertEqual(300, time_obj.get_min_interval())
    def _wait_timestamp(pattern, start_time, freq):
        if not isinstance(freq, int) or freq <= 0:
            return 0

        cur_time = copy.deepcopy(start_time)
        cal_obj = calendar_time.ICal(start_time, pattern)
        for i in range(freq):
            next_time = cal_obj.compute_next_time(cur_time)
            cur_time = next_time
        return (next_time - start_time).seconds