コード例 #1
0
    def get_next_run_time(self, now: datetime, previous_run_time: datetime = None) -> Optional[datetime]:
        if previous_run_time:
            start_time = previous_run_time + timedelta(seconds=1)
        elif self.start_time:
            start_time = max(now, self.start_time)
        else:
            start_time = now

        fieldnum = 0
        next_time = datetime_ceil(start_time).astimezone(self.timezone)
        while 0 <= fieldnum < len(self.fields):
            field = self.fields[fieldnum]
            curr_value = field.get_value(next_time)
            next_value = field.get_next_value(next_time)

            if next_value is None:
                # No valid value was found
                next_time, fieldnum = self._increment_field_value(next_time, fieldnum - 1)
            elif next_value > curr_value:
                # A valid, but higher than the starting value, was found
                if field.real:
                    next_time = self._set_field_value(next_time, fieldnum, next_value)
                    fieldnum += 1
                else:
                    next_time, fieldnum = self._increment_field_value(next_time, fieldnum)
            else:
                # A valid value was found, no changes necessary
                fieldnum += 1

            # Return if the date has rolled past the end date
            if self.end_time and next_time > self.end_time:
                return None

        return next_time if fieldnum >= 0 else None
コード例 #2
0
    def get_next_run_time(
            self,
            now: datetime,
            previous_run_time: datetime = None) -> Optional[datetime]:
        if previous_run_time:
            start_time = previous_run_time + timedelta(seconds=1)
        elif self.start_time:
            start_time = max(now, self.start_time)
        else:
            start_time = now

        fieldnum = 0
        next_time = datetime_ceil(start_time).astimezone(self.timezone)
        while 0 <= fieldnum < len(self.fields):
            field = self.fields[fieldnum]
            curr_value = field.get_value(next_time)
            next_value = field.get_next_value(next_time)

            if next_value is None:
                # No valid value was found
                next_time, fieldnum = self._increment_field_value(
                    next_time, fieldnum - 1)
            elif next_value > curr_value:
                # A valid, but higher than the starting value, was found
                if field.real:
                    next_time = self._set_field_value(next_time, fieldnum,
                                                      next_value)
                    fieldnum += 1
                else:
                    next_time, fieldnum = self._increment_field_value(
                        next_time, fieldnum)
            else:
                # A valid value was found, no changes necessary
                fieldnum += 1

            # Return if the date has rolled past the end date
            if self.end_time and next_time > self.end_time:
                return None

        return next_time if fieldnum >= 0 else None
コード例 #3
0
def test_datetime_ceil(input, expected):
    assert datetime_ceil(input) == expected
コード例 #4
0
def test_datetime_ceil(input, expected):
    assert datetime_ceil(input) == expected