From 8b491ba877f0049bc35b2a6bb904f318e2c452f7 Mon Sep 17 00:00:00 2001 From: HarHarLinks <2803622+HarHarLinks@users.noreply.github.com> Date: Sun, 11 Feb 2024 18:44:56 +0100 Subject: [PATCH 1/2] fix LMT issue #127 --- matrix_reminder_bot/bot_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix_reminder_bot/bot_commands.py b/matrix_reminder_bot/bot_commands.py index 1b18d9b..58ff70a 100644 --- a/matrix_reminder_bot/bot_commands.py +++ b/matrix_reminder_bot/bot_commands.py @@ -65,7 +65,7 @@ def _parse_str_to_time(time_str: str, tz_aware: bool = True) -> datetime: # Disallow times in the past tzinfo = pytz.timezone(CONFIG.timezone) - if time.replace(tzinfo=tzinfo) < _get_datetime_now(CONFIG.timezone): + if tzinfo.localize(time) < _get_datetime_now(CONFIG.timezone): raise CommandError(f"The given time '{time_str}' is in the past.") # Round datetime object to the nearest second for nicer display From b77be1872716986ddbf82c89f3d953944c73b2e2 Mon Sep 17 00:00:00 2001 From: HarHarLinks <2803622+HarHarLinks@users.noreply.github.com> Date: Sun, 11 Feb 2024 19:12:27 +0100 Subject: [PATCH 2/2] fix pytz API usage --- matrix_reminder_bot/bot_commands.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/matrix_reminder_bot/bot_commands.py b/matrix_reminder_bot/bot_commands.py index 58ff70a..1d408ec 100644 --- a/matrix_reminder_bot/bot_commands.py +++ b/matrix_reminder_bot/bot_commands.py @@ -204,10 +204,8 @@ async def _confirm_reminder(self, reminder: Reminder): return - # Convert a timedelta to a formatted time (ex. May 25 2020, 01:31) - start_time = reminder.start_time.replace( - tzinfo=pytz.timezone(reminder.timezone) - ) + # Convert a datetime to a formatted time (ex. May 25 2020, 01:31) + start_time = pytz.timezone(reminder.timezone).localize(reminder.start_time) human_readable_start_time = start_time.strftime("%b %d %Y, %H:%M") # Get a textual representation of who will be notified by this reminder