From 34e2e932729150da7e4e4821468131132595e803 Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Tue, 5 Dec 2023 16:47:14 +0200 Subject: [PATCH] Use datetime.timezone.utc --- smartmin/templatetags/smartmin.py | 6 +++--- test_runner/blog/tests.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/smartmin/templatetags/smartmin.py b/smartmin/templatetags/smartmin.py index d628718..1cab462 100644 --- a/smartmin/templatetags/smartmin.py +++ b/smartmin/templatetags/smartmin.py @@ -34,7 +34,7 @@ def format_datetime(time): """ user_time_zone = timezone.get_current_timezone() if time.tzinfo is None: - time = time.replace(tzinfo=timezone.utc) + time = time.replace(tzinfo=datetime.timezone.utc) user_time_zone = zoneinfo.ZoneInfo(getattr(settings, "USER_TIME_ZONE", "GMT")) time = time.astimezone(user_time_zone) @@ -164,7 +164,7 @@ def map(string, args): @register.filter def gmail_time(dtime, now=None): if dtime.tzinfo is None: - dtime = dtime.replace(tzinfo=timezone.utc) + dtime = dtime.replace(tzinfo=datetime.timezone.utc) user_time_zone = zoneinfo.ZoneInfo(getattr(settings, "USER_TIME_ZONE", "GMT")) dtime = dtime.astimezone(user_time_zone) else: @@ -174,7 +174,7 @@ def gmail_time(dtime, now=None): now = timezone.now() if now.tzinfo is None: - now = now.replace(tzinfo=timezone.utc) + now = now.replace(tzinfo=datetime.timezone.utc) twelve_hours_ago = now - timedelta(hours=12) diff --git a/test_runner/blog/tests.py b/test_runner/blog/tests.py index d7943bd..3a7a10a 100644 --- a/test_runner/blog/tests.py +++ b/test_runner/blog/tests.py @@ -1141,7 +1141,7 @@ def setUp(self): def test_value_from_view(self): context = dict(view=self.read_view, object=self.post) self.assertEquals(self.post.title, get_value_from_view(context, "title")) - local_created = self.post.created_on.replace(tzinfo=timezone.utc).astimezone(ZoneInfo("Africa/Kigali")) + local_created = self.post.created_on.replace(tzinfo=datetime.timezone.utc).astimezone(ZoneInfo("Africa/Kigali")) self.assertEquals(local_created.strftime("%b %d, %Y %H:%M"), get_value_from_view(context, "created_on")) def test_view_as_json(self): @@ -1183,7 +1183,7 @@ def test_gmail_time(self): self.assertEquals(test_date.strftime("%b") + " 2", gmail_time(test_date, now)) # but a different year is different - jan_2 = datetime(2012, 1, 2, 17, 5, 0, 0).replace(tzinfo=timezone.utc) + jan_2 = datetime(2012, 1, 2, 17, 5, 0, 0).replace(tzinfo=datetime.timezone.utc) self.assertEquals("2/1/12", gmail_time(jan_2, now)) def test_user_as_string(self):