Skip to content

Commit

Permalink
Bugfix: tuesday.at('HH:MM:SS') where HMS=now+10s doesn't run today #331
Browse files Browse the repository at this point in the history
… (#337)

* Fix for issue #331 - missing parenthnesses

missing parenthnesses causing that condition was met also for unit != 'hours'

* flake8 fix

* Add test: Job scheduled to run on a specific day at a specific time, scheduled during that day, should run today (see #331).

Co-authored-by: sijmenhuizenga <sijmenhuizenga@gmail.com>
  • Loading branch information
qmorek and SijmenHuizenga committed Nov 26, 2020
1 parent a6fdc61 commit f19998b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions schedule/__init__.py
Expand Up @@ -544,9 +544,11 @@ def _schedule_next_run(self):
self.interval == 1):
self.next_run = self.next_run - datetime.timedelta(days=1)
elif self.unit == 'hours' \
and self.at_time.minute > now.minute \
or (self.at_time.minute == now.minute
and self.at_time.second > now.second):
and (
self.at_time.minute > now.minute
or (self.at_time.minute == now.minute
and self.at_time.second > now.second)
):
self.next_run = self.next_run - datetime.timedelta(hours=1)
elif self.unit == 'minutes' \
and self.at_time.second > now.second:
Expand Down
21 changes: 21 additions & 0 deletions test_schedule.py
Expand Up @@ -194,6 +194,27 @@ def test_at_time(self):
with self.assertRaises(IntervalError):
every(interval=2).sunday

def test_weekday_at_todady(self):
mock_job = make_mock_job()

# This date is a wednesday
with mock_datetime(2020, 11, 25, 22, 38, 5):
job = every().wednesday.at('22:38:10').do(mock_job)
assert job.next_run.hour == 22
assert job.next_run.minute == 38
assert job.next_run.second == 10
assert job.next_run.year == 2020
assert job.next_run.month == 11
assert job.next_run.day == 25

job = every().wednesday.at('22:39').do(mock_job)
assert job.next_run.hour == 22
assert job.next_run.minute == 39
assert job.next_run.second == 00
assert job.next_run.year == 2020
assert job.next_run.month == 11
assert job.next_run.day == 25

def test_at_time_hour(self):
with mock_datetime(2010, 1, 6, 12, 20):
mock_job = make_mock_job()
Expand Down

0 comments on commit f19998b

Please sign in to comment.