diff options
author | 2021-05-17 22:35:58 +0100 | |
---|---|---|
committer | 2021-05-17 22:35:58 +0100 | |
commit | 1b21117a300d9191dec9f286e3bbd1c8e336e340 (patch) | |
tree | 34b9d4f53a547af90ab5991f28f80cb4f13c905a /bot/exts | |
parent | Merge pull request #726 from Objectivitix/main (diff) |
Change AoC helpers to use arrow over pytz
This is the only place in the codebase that uses pytz, so we can remove the
dependancy by chaging this to use arrow.
I chose to use America/Chicago arbitrarily, for no other reason that being the
first tz google returned that was in EST.
Diffstat (limited to 'bot/exts')
-rw-r--r-- | bot/exts/christmas/advent_of_code/_helpers.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/bot/exts/christmas/advent_of_code/_helpers.py b/bot/exts/christmas/advent_of_code/_helpers.py index f4a258c0..99688400 100644 --- a/bot/exts/christmas/advent_of_code/_helpers.py +++ b/bot/exts/christmas/advent_of_code/_helpers.py @@ -9,8 +9,8 @@ import typing from typing import Tuple import aiohttp +import arrow import discord -import pytz from bot.bot import Bot from bot.constants import AdventOfCode, Channels, Colours @@ -48,7 +48,7 @@ AOC_EMBED_THUMBNAIL = ( ) # Create an easy constant for the EST timezone -EST = pytz.timezone("EST") +EST = "America/Chicago" # Step size for the challenge countdown status COUNTDOWN_STEP = 60 * 5 @@ -395,13 +395,13 @@ def is_in_advent() -> bool: something for the next Advent of Code challenge should run. As the puzzle published on the 25th is the last puzzle, this check excludes that date. """ - return datetime.datetime.now(EST).day in range(1, 25) and datetime.datetime.now(EST).month == 12 + return arrow.now(EST).day in range(1, 25) and arrow.now(EST).month == 12 def time_left_to_est_midnight() -> Tuple[datetime.datetime, datetime.timedelta]: """Calculate the amount of time left until midnight EST/UTC-5.""" # Change all time properties back to 00:00 - todays_midnight = datetime.datetime.now(EST).replace( + todays_midnight = arrow.now(EST).replace( microsecond=0, second=0, minute=0, @@ -412,7 +412,7 @@ def time_left_to_est_midnight() -> Tuple[datetime.datetime, datetime.timedelta]: tomorrow = todays_midnight + datetime.timedelta(days=1) # Calculate the timedelta between the current time and midnight - return tomorrow, tomorrow - datetime.datetime.now(EST) + return tomorrow, tomorrow - arrow.now(EST) async def wait_for_advent_of_code(*, hours_before: int = 1) -> None: @@ -430,9 +430,9 @@ async def wait_for_advent_of_code(*, hours_before: int = 1) -> None: if we're already past the Advent of Code edition the bot is currently configured for. """ - start = datetime.datetime(AdventOfCode.year, 12, 1, 0, 0, 0, tzinfo=EST) + start = arrow.get(datetime.datetime(AdventOfCode.year, 12, 1), EST) target = start - datetime.timedelta(hours=hours_before) - now = datetime.datetime.now(EST) + now = arrow.now(EST) # If we've already reached or passed to target, we # simply return immediately. @@ -474,10 +474,10 @@ async def countdown_status(bot: Bot) -> None: # sleeping for the entire year, it will only wait in the currently # configured year. This means that the task will only start hibernating once # we start preparing the next event by changing environment variables. - last_challenge = datetime.datetime(AdventOfCode.year, 12, 25, 0, 0, 0, tzinfo=EST) + last_challenge = arrow.get(datetime.datetime(AdventOfCode.year, 12, 25), EST) end = last_challenge + datetime.timedelta(hours=1) - while datetime.datetime.now(EST) < end: + while arrow.now(EST) < end: _, time_left = time_left_to_est_midnight() aligned_seconds = int(math.ceil(time_left.seconds / COUNTDOWN_STEP)) * COUNTDOWN_STEP @@ -534,8 +534,8 @@ async def new_puzzle_notification(bot: Bot) -> None: # The last event day is 25 December, so we only have to schedule # a reminder if the current day is before 25 December. - end = datetime.datetime(AdventOfCode.year, 12, 25, tzinfo=EST) - while datetime.datetime.now(EST) < end: + end = arrow.get(datetime.datetime(AdventOfCode.year, 12, 25), EST) + while arrow.now(EST) < end: log.trace("Started puzzle notification loop.") tomorrow, time_left = time_left_to_est_midnight() |