From bdfcb600a0c05f3294bb18516805ce4082412fe9 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Thu, 24 Aug 2023 22:18:55 +0100 Subject: [PATCH 1/3] Fix deprecation in Python 3.12 --- freezegun/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freezegun/api.py b/freezegun/api.py index e33b99e8..1bd4cd11 100644 --- a/freezegun/api.py +++ b/freezegun/api.py @@ -470,7 +470,7 @@ def _parse_time_to_freeze(time_to_freeze_str): elif isinstance(time_to_freeze_str, datetime.date): time_to_freeze = datetime.datetime.combine(time_to_freeze_str, datetime.time()) elif isinstance(time_to_freeze_str, datetime.timedelta): - time_to_freeze = datetime.datetime.utcnow() + time_to_freeze_str + time_to_freeze = datetime.datetime.now(datetime.UTC) + time_to_freeze_str else: time_to_freeze = parser.parse(time_to_freeze_str) From 50c0bcd8a602ae5cff3a6feb7d78cd91efeb8229 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Thu, 24 Aug 2023 22:21:32 +0100 Subject: [PATCH 2/3] Work on Python <3.11 --- freezegun/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freezegun/api.py b/freezegun/api.py index 1bd4cd11..459aed26 100644 --- a/freezegun/api.py +++ b/freezegun/api.py @@ -470,7 +470,7 @@ def _parse_time_to_freeze(time_to_freeze_str): elif isinstance(time_to_freeze_str, datetime.date): time_to_freeze = datetime.datetime.combine(time_to_freeze_str, datetime.time()) elif isinstance(time_to_freeze_str, datetime.timedelta): - time_to_freeze = datetime.datetime.now(datetime.UTC) + time_to_freeze_str + time_to_freeze = datetime.datetime.now(datetime.timezone.utc) + time_to_freeze_str else: time_to_freeze = parser.parse(time_to_freeze_str) From 00f62cec822ee77367e913a60d74b3f779cef9fe Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Fri, 25 Aug 2023 01:28:58 +0100 Subject: [PATCH 3/3] Update api.py --- freezegun/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freezegun/api.py b/freezegun/api.py index 459aed26..f732ff8c 100644 --- a/freezegun/api.py +++ b/freezegun/api.py @@ -408,7 +408,7 @@ def today(cls): @classmethod def utcnow(cls): - result = cls._time_to_freeze() or real_datetime.utcnow() + result = cls._time_to_freeze() or real_datetime.now(datetime.timezone.utc) return datetime_to_fakedatetime(result) @staticmethod @@ -463,7 +463,7 @@ def _parse_time_to_freeze(time_to_freeze_str): :returns: a naive ``datetime.datetime`` object """ if time_to_freeze_str is None: - time_to_freeze_str = datetime.datetime.utcnow() + time_to_freeze_str = datetime.datetime.now(datetime.timezone.utc) if isinstance(time_to_freeze_str, datetime.datetime): time_to_freeze = time_to_freeze_str