aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2020-09-30 22:51:22 +0100
committerGravatar Joe Banks <[email protected]>2020-09-30 22:51:22 +0100
commite2062ccde0d566503980496e4098a218bc1c111b (patch)
tree206a8a2a8b70d40d7903a87be3302560aca871af
parentUpdate t-shirt references to t-shirts and trees! (diff)
Update timeleft to not be locked to October
-rw-r--r--bot/exts/halloween/timeleft.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/bot/exts/halloween/timeleft.py b/bot/exts/halloween/timeleft.py
index 295acc89..ef436057 100644
--- a/bot/exts/halloween/timeleft.py
+++ b/bot/exts/halloween/timeleft.py
@@ -13,20 +13,23 @@ class TimeLeft(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
- @staticmethod
- def in_october() -> bool:
- """Return True if the current month is October."""
- return datetime.utcnow().month == 10
+ def in_hacktober(self) -> bool:
+ """Return True if the current time is within Hacktoberfest."""
+ _, end, start = self.load_date()
+
+ now = datetime.utcnow()
+
+ return start <= now <= end
@staticmethod
- def load_date() -> Tuple[int, datetime, datetime]:
+ def load_date() -> Tuple[datetime, datetime, datetime]:
"""Return of a tuple of the current time and the end and start times of the next October."""
now = datetime.utcnow()
year = now.year
if now.month > 10:
year += 1
- end = datetime(year, 11, 1, 11, 59, 59)
- start = datetime(year, 10, 1)
+ end = datetime(year, 11, 1, 12) # November 1st 12:00 (UTC-12:00)
+ start = datetime(year, 9, 30, 10) # September 30th 10:00 (UTC+14:00)
return now, end, start
@commands.command()
@@ -35,16 +38,20 @@ class TimeLeft(commands.Cog):
Calculates the time left until the end of Hacktober.
Whilst in October, displays the days, hours and minutes left.
- Only displays the days left until the beginning and end whilst in a different month
+ Only displays the days left until the beginning and end whilst in a different month.
+
+ This factors in that Hacktoberfest starts when it is October anywhere in the world
+ and ends with the same rules. It treats the start as UTC+14:00 and the end as
+ UTC-12.
"""
now, end, start = self.load_date()
diff = end - now
days, seconds = diff.days, diff.seconds
- if self.in_october():
+ if self.in_hacktober():
minutes = seconds // 60
hours, minutes = divmod(minutes, 60)
- await ctx.send(f"There is currently only {days} days, {hours} hours and {minutes}"
- "minutes left until the end of Hacktober.")
+ await ctx.send(f"There are {days} days, {hours} hours and {minutes}"
+ " minutes left until the end of Hacktober.")
else:
start_diff = start - now
start_days = start_diff.days