diff options
| -rw-r--r-- | bot/utils/scheduling.py | 8 | 
1 files changed, 6 insertions, 2 deletions
diff --git a/bot/utils/scheduling.py b/bot/utils/scheduling.py index 4dd036e4f..b3f62257a 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 we 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)  |