Skip to content

Commit

Permalink
Merge branch 'master' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby authored Nov 27, 2023
2 parents 24614d3 + 2437c7e commit 0fe4e20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ These changes are available on the `master` branch, but have not yet been releas
`None`. ([#2219](https://github.com/Pycord-Development/pycord/pull/2219))
- Fixed ffmpeg being terminated prematurely when piping audio stream.
([#2240](https://github.com/Pycord-Development/pycord/pull/2240))
- Fixed tasks looping infinitely when `tzinfo` is neither `None` nor UTC.
([#2196](https://github.com/Pycord-Development/pycord/pull/2196))

## [2.4.1] - 2023-03-20

Expand Down
18 changes: 13 additions & 5 deletions discord/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def _get_next_sleep_time(self) -> datetime.datetime:
if self._current_loop == 0:
# if we're at the last index on the first iteration, we need to sleep until tomorrow
return datetime.datetime.combine(
datetime.datetime.now(datetime.timezone.utc)
datetime.datetime.now(self._time[0].tzinfo or datetime.timezone.utc)
+ datetime.timedelta(days=1),
self._time[0],
)
Expand All @@ -584,18 +584,26 @@ def _get_next_sleep_time(self) -> datetime.datetime:

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

next_date = cast(datetime.datetime, self._last_iteration)
next_date = cast(
datetime.datetime, self._last_iteration.astimezone(next_time.tzinfo)
)
if next_time < next_date.timetz():
next_date += datetime.timedelta(days=1)

Expand Down

0 comments on commit 0fe4e20

Please sign in to comment.