From 8350b01d85f2122a03dbe7a5f0fb95d0a840a494 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Mon, 29 Nov 2021 22:12:53 +0100 Subject: [PATCH] Fix incorrect timeformatting --- cogs/slash/db_slash.py | 2 +- functions/timeFormatters.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cogs/slash/db_slash.py b/cogs/slash/db_slash.py index bed6213..24bad49 100644 --- a/cogs/slash/db_slash.py +++ b/cogs/slash/db_slash.py @@ -66,7 +66,7 @@ class Slash(commands.Cog): if time.count(":") == 1: time += ":00" - dt = fromString(f"{date} {time}", formatString="%d/%m/%Y %H:%M:%S") + dt = fromString(f"{date} {time}", formatString="%d/%m/%Y %H:%M:%S", tzinfo=None) # Add year & course if necessary if str(year) not in deadlines: diff --git a/functions/timeFormatters.py b/functions/timeFormatters.py index 1d7788a..e6a880c 100644 --- a/functions/timeFormatters.py +++ b/functions/timeFormatters.py @@ -157,7 +157,12 @@ def fromString(timeString: str, formatString="%d/%m/%Y", tzinfo=pytz.timezone("E """ Constructs a datetime object from an input string """ - return datetime.datetime.strptime(timeString, formatString).replace(tzinfo=tzinfo) + dt = datetime.datetime.strptime(timeString, formatString) + + if tzinfo is not None: + dt = dt.replace(tzinfo=tzinfo) + + return dt def fromArray(data: List[int]) -> datetime: