Skip to content

Commit

Permalink
Bugfix for task.loop
Browse files Browse the repository at this point in the history
Makes task.loop check if the time must be on this day or the next
  • Loading branch information
veni-vidi-code authored Nov 13, 2021
1 parent 65de7f3 commit ef94e38
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions discord/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,13 @@ def _get_next_sleep_time(self) -> datetime.datetime:

if self._current_loop == 0:
self._time_index += 1
return datetime.datetime.combine(datetime.datetime.now(datetime.timezone.utc), next_time)
if next_time > datetime.datetime.now(datetime.timezone.utc).timetz():
return datetime.datetime.combine(datetime.datetime.now(datetime.timezone.utc), next_time)
else:
return datetime.datetime.combine(datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1), next_time)

next_date = self._last_iteration
if self._time_index == 0:
# we can assume that the earliest time should be scheduled for "tomorrow"
next_date = cast(datetime.datetime, self._last_iteration)
if next_time < next_date.timetz():
next_date += datetime.timedelta(days=1)

self._time_index += 1
Expand Down

0 comments on commit ef94e38

Please sign in to comment.