Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using self.next_run.time() instead of self.at_time when "making sure we run at the specified time *today*" #583

Merged
merged 12 commits into from
Oct 1, 2023
2 changes: 1 addition & 1 deletion schedule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ def _schedule_next_run(self) -> None:
now = datetime.datetime.now()
if (
self.unit == "days"
and self.at_time > now.time()
and self.next_run.time() > now.time()
and self.interval == 1
):
self.next_run = self.next_run - datetime.timedelta(days=1)
Expand Down
24 changes: 24 additions & 0 deletions test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,20 @@ def test_at_timezone(self):
# Expected to run India time: feb-2 06:30
# Next run Berlin time: feb-2 02:00
next = every().day.at("06:30", "Asia/Kolkata").do(mock_job).next_run
assert next.day == 2
assert next.hour == 2
assert next.minute == 0

with mock_datetime(2023, 4, 14, 4, 50):
# Current Berlin time: april-14 04:50 (local) (during daylight saving)
# Current US/Central time: april-13 21:50
# Expected to run US/Central time: april-14 00:00
# Next run Berlin time: april-14 07:00
next = every().day.at("00:00", "US/Central").do(mock_job).next_run
assert next.day == 14
assert next.hour == 7
assert next.minute == 0

with mock_datetime(2022, 4, 8, 10, 0):
# Current Berlin time: 10:00 (local) (during daylight saving)
# Current NY time: 04:00
Expand All @@ -559,6 +570,19 @@ def test_at_timezone(self):
assert next.hour == 15
assert next.minute == 30

with mock_datetime(2022, 3, 20, 10, 0):
# Current Berlin time: 10:00 (local) (NOT during daylight saving)
# Current Krasnoyarsk time: 16:00
# Expected to run Krasnoyarsk time: mar-21 11:00
# Next run Berlin time: mar-21 05:00
# Expected idle seconds: 68400
schedule.clear()
every().day.at("11:00", "Asia/Krasnoyarsk").do(mock_job)
expected_delta = (
datetime.datetime(2022, 3, 21, 5, 0) - datetime.datetime.now()
)
assert schedule.idle_seconds() == expected_delta.total_seconds()

with self.assertRaises(pytz.exceptions.UnknownTimeZoneError):
every().day.at("10:30", "FakeZone").do(mock_job)

Expand Down