aboutsummaryrefslogtreecommitdiffstats
path: root/bot/utils/scheduling.py
diff options
context:
space:
mode:
authorGravatar Matteo Bertucci <[email protected]>2021-04-06 17:13:16 +0200
committerGravatar GitHub <[email protected]>2021-04-06 17:13:16 +0200
commit44d6a351df197a6184bcb2ece71277f74b6374c3 (patch)
tree4fd9eb5502d5be4bba200b2fd8aeadd55e6f4ce4 /bot/utils/scheduling.py
parentMerge pull request #1499 from bsoyka/user-colors (diff)
parentMerge branch 'main' into stream-and-revokestream-commands (diff)
Merge pull request #1493 from python-discord/stream-and-revokestream-commands
Stream and revokestream commands
Diffstat (limited to '')
-rw-r--r--bot/utils/scheduling.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/bot/utils/scheduling.py b/bot/utils/scheduling.py
index 4dd036e4f..6843bae88 100644
--- a/bot/utils/scheduling.py
+++ b/bot/utils/scheduling.py
@@ -59,14 +59,18 @@ class Scheduler:
def schedule_at(self, time: datetime, task_id: t.Hashable, coroutine: t.Coroutine) -> None:
"""
- Schedule `coroutine` to be executed at the given naïve UTC `time`.
+ Schedule `coroutine` to be executed at the given `time`.
+
+ If `time` is timezone aware, then use that timezone to calculate now() when subtracting.
+ If `time` is naïve, then use UTC.
If `time` is in the past, schedule `coroutine` immediately.
If a task with `task_id` already exists, close `coroutine` instead of scheduling it. This
prevents unawaited coroutine warnings. Don't pass a coroutine that'll be re-used elsewhere.
"""
- delay = (time - datetime.utcnow()).total_seconds()
+ now_datetime = datetime.now(time.tzinfo) if time.tzinfo else datetime.utcnow()
+ delay = (time - now_datetime).total_seconds()
if delay > 0:
coroutine = self._await_later(delay, task_id, coroutine)