aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Mark <[email protected]>2019-11-02 20:23:49 -0700
committerGravatar GitHub <[email protected]>2019-11-02 20:23:49 -0700
commit532cd73194a1992e6dbe28de9f304f9c5adc661e (patch)
tree5f90350c6eec110503ba6a4b35f56da0754d9df5
parentMerge pull request #629 from python-discord/unittest-helpers-proper-child-mock (diff)
parentUse timedelta to correctly calculate next midnight (diff)
Merge pull request #638 from loksonarius/fix-reddit-cog-sleep
Use timedelta to correctly calculate next midnight
-rw-r--r--bot/cogs/reddit.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/bot/cogs/reddit.py b/bot/cogs/reddit.py
index f947a7d78..0d06e9c26 100644
--- a/bot/cogs/reddit.py
+++ b/bot/cogs/reddit.py
@@ -2,7 +2,7 @@ import asyncio
import logging
import random
import textwrap
-from datetime import datetime
+from datetime import datetime, timedelta
from typing import List
from discord import Colour, Embed, TextChannel
@@ -130,7 +130,8 @@ class Reddit(Cog):
"""Post the top 5 posts daily, and the top 5 posts weekly."""
# once we upgrade to d.py 1.3 this can be removed and the loop can use the `time=datetime.time.min` parameter
now = datetime.utcnow()
- midnight_tomorrow = now.replace(day=now.day + 1, hour=0, minute=0, second=0)
+ tomorrow = now + timedelta(days=1)
+ midnight_tomorrow = tomorrow.replace(hour=0, minute=0, second=0)
seconds_until = (midnight_tomorrow - now).total_seconds()
await asyncio.sleep(seconds_until)