def __init__(self, *, year: Union[int, str] = None, month: Union[int, str] = None, day: Union[int, str] = None, week: Union[int, str] = None, day_of_week: Union[int, str] = None, hour: Union[int, str] = None, minute: Union[int, str] = None, second: Union[int, str] = None, start_time: datetime = None, end_time: datetime = None, **kwargs): assert check_argument_types() super().__init__(**kwargs) self.start_time = convert_to_timezone(start_time, self.timezone) self.end_time = convert_to_timezone(end_time, self.timezone) self.fields = self._create_fields(year=year, month=month, week=week, day=day, day_of_week=day_of_week, hour=hour, minute=minute, second=second) if start_time and end_time and start_time > end_time: raise ValueError('end_time cannot be earlier than start_time')
def __init__(self, *, weeks: int = 0, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0, start_time: datetime = None, end_time: datetime = None, **kwargs): assert check_argument_types() super().__init__(**kwargs) self.start_time = convert_to_timezone(start_time, self.timezone) self.end_time = convert_to_timezone(end_time, self.timezone) self.interval = timedelta(weeks=weeks, days=days, hours=hours, minutes=minutes, seconds=seconds) if self.interval.total_seconds() < 1: raise ValueError('interval must be at least 1 second long') if start_time and end_time and start_time > end_time: raise ValueError('end_time cannot be earlier than start_time')
def test_convert_to_timezone(input, expected, timezone): if expected: expected = timezone.localize(expected) assert convert_to_timezone(input, timezone) == expected
def test_get_next_run_time(schedule: CronSchedule, previous_time, now, expected, timezone: DstTzInfo): previous_time = convert_to_timezone(previous_time, timezone) now = convert_to_timezone(now, timezone) expected = convert_to_timezone(expected, timezone) assert schedule.get_next_run_time(now, previous_time) == expected
def __init__(self, run_time: datetime, **kwargs): assert check_argument_types() super().__init__(**kwargs) self.run_time = convert_to_timezone(run_time, self.timezone)