Ejemplo n.º 1
0
def calculate_effective_schedule_start_dt(schedule):
    """
    Calculation of the first start date to improve performance
    """
    programme_start_dt = schedule.programme.start_dt
    programme_end_dt = schedule.programme.end_dt

    # If there are no rrules
    if not schedule.has_recurrences():
        if programme_start_dt and programme_start_dt > schedule.start_dt:
            return None
        if programme_end_dt and schedule.start_dt > programme_end_dt:
            return None
        return schedule.start_dt

    # Get first date
    after_dt = schedule.start_dt
    if programme_start_dt:
        after_dt = max(schedule.start_dt, programme_start_dt)
    first_start_dt = fix_recurrence_dst(recurrence_after(
        schedule.recurrences, transform_dt_to_default_tz(after_dt), transform_dt_to_default_tz(schedule.start_dt)))
    if first_start_dt:
        if programme_end_dt and programme_end_dt < first_start_dt:
            return None
        return first_start_dt
    return None
Ejemplo n.º 2
0
def calculate_effective_schedule_start_dt(schedule):
    """
    Calculation of the first start date to improve performance
    """
    programme_start_dt = schedule.programme.start_dt
    programme_end_dt = schedule.programme.end_dt

    # If there are no rrules
    if not schedule.has_recurrences():
        if programme_start_dt and programme_start_dt > schedule.start_dt:
            return None
        if programme_end_dt and schedule.start_dt > programme_end_dt:
            return None
        return schedule.start_dt

    # Get first date
    after_dt = schedule.start_dt
    if programme_start_dt:
        after_dt = max(schedule.start_dt, programme_start_dt)
    first_start_dt = fix_recurrence_dst(recurrence_after(
        schedule.recurrences, transform_dt_to_default_tz(after_dt), transform_dt_to_default_tz(schedule.start_dt)))
    if first_start_dt:
        if programme_end_dt and programme_end_dt < first_start_dt:
            return None
        return first_start_dt
    return None
Ejemplo n.º 3
0
 def date_after(self, after):
     after_date = self._merge_after(after)
     if not after_date:
         return
     after_date = transform_dt_to_default_tz(after_date)
     start_dt = transform_dt_to_default_tz(self.start_dt)
     date = recurrence_after(self.recurrences, after_date, start_dt)
     return fix_recurrence_dst(date)
Ejemplo n.º 4
0
 def date_after(self, after):
     after_date = self._merge_after(after)
     if not after_date:
         return
     after_date = transform_dt_to_default_tz(after_date)
     start_dt = transform_dt_to_default_tz(self.start_dt)
     date = recurrence_after(self.recurrences, after_date, start_dt)
     return fix_recurrence_dst(date)
Ejemplo n.º 5
0
    def test_impossible_recurrence_after(self):
        """
        Testing error calling after and function wrapper to solve it (recurrence_after)
        """
        start_dt = datetime.datetime(2014, 1, 20, 14, 0, 0)
        until_dt = datetime.datetime(2014, 1, 19, 14, 0, 0)
        daily_recurrence = recurrence.Recurrence(
            rrules=[recurrence.Rule(recurrence.DAILY, until=until_dt)])

        dt = daily_recurrence.after(start_dt, True, dtstart=start_dt)
        self.assertEqual(start_dt, dt)  # wrong!

        self.assertIsNone(recurrence_after(daily_recurrence, start_dt, start_dt))
Ejemplo n.º 6
0
    def test_impossible_recurrence_after(self):
        """
        Testing error calling after and function wrapper to solve it (recurrence_after)
        """
        start_dt = datetime.datetime(2014, 1, 20, 14, 0, 0)
        until_dt = datetime.datetime(2014, 1, 19, 14, 0, 0)
        daily_recurrence = recurrence.Recurrence(
            rrules=[recurrence.Rule(recurrence.DAILY, until=until_dt)])

        dt = daily_recurrence.after(start_dt, True, dtstart=start_dt)
        self.assertEqual(start_dt, dt)  # wrong!

        self.assertIsNone(
            recurrence_after(daily_recurrence, start_dt, start_dt))