From e98349fb6317c584c929843c8da613a38860d25c Mon Sep 17 00:00:00 2001 From: Mathieu Dupuy Date: Thu, 11 Apr 2024 14:36:43 +0200 Subject: [PATCH] force utc timezone for datetime.fromisoformat --- iredis/completers.py | 4 ++-- tests/unittests/test_completers.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iredis/completers.py b/iredis/completers.py index 30100aef..b4120108 100644 --- a/iredis/completers.py +++ b/iredis/completers.py @@ -1,6 +1,6 @@ import logging from typing import Iterable -from datetime import datetime +from datetime import datetime, timezone from dateutil.relativedelta import relativedelta from prompt_toolkit.completion import ( @@ -123,7 +123,7 @@ def _completion_humanize_time(self, document: Document) -> Iterable[Completion]: def _completion_formatted_time(self, document: Document) -> Iterable[Completion]: text = document.text try: - dt = datetime.fromisoformat(text) + dt = datetime.fromisoformat(text).replace(tzinfo=timezone.utc) except Exception: return yield Completion( diff --git a/tests/unittests/test_completers.py b/tests/unittests/test_completers.py index 5443a48c..71f0234c 100644 --- a/tests/unittests/test_completers.py +++ b/tests/unittests/test_completers.py @@ -347,7 +347,7 @@ def test_timestamp_completer_datetime_format_time_completion(): text="1581033600000", start_position=-10, display=FormattedText([("", "1581033600000")]), - display_meta="2020-02-07T00:00:00+00:00", + display_meta="2020-02-07 00:00:00+00:00", ) ]