mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
[tasks] Compare using full datetime rather than sole time
Comparisons using just the time object without an attached date are pretty buggy and incomplete -- comparisons only make sense when given a particular instant of time. Ref: #7676
This commit is contained in:
parent
58ad146a4e
commit
a339e01047
@ -603,9 +603,16 @@ class Loop(Generic[LF]):
|
||||
# to calculate the next time index from
|
||||
|
||||
# pre-condition: self._time is set
|
||||
time_now = now.timetz()
|
||||
|
||||
# Sole time comparisons are apparently broken, therefore, attach today's date
|
||||
# to it in order to make the comparisons make sense.
|
||||
# For example, if given a list of times [0, 3, 18]
|
||||
# If it's 04:00 today then we know we have to wait until 18:00 today
|
||||
# If it's 19:00 today then we know we we have to wait until 00:00 tomorrow
|
||||
date = now.date()
|
||||
for idx, time in enumerate(self._time):
|
||||
if time >= time_now:
|
||||
start_time = datetime.datetime.combine(date, time, tzinfo=time.tzinfo)
|
||||
if start_time >= now:
|
||||
return idx
|
||||
else:
|
||||
return None
|
||||
|
Loading…
x
Reference in New Issue
Block a user