diff --git a/smartmin/models.py b/smartmin/models.py index 2289fb5..0e6d64f 100644 --- a/smartmin/models.py +++ b/smartmin/models.py @@ -2,7 +2,7 @@ import json import traceback import zoneinfo -from datetime import datetime +from datetime import datetime, timezone as dt_timezone from xlrd import XL_CELL_DATE, XLRDError, open_workbook, xldate_as_tuple @@ -222,7 +222,7 @@ def import_xls(cls, filename, user, import_params, log=None, import_results=None naive_timezone = ( zoneinfo.ZoneInfo(import_params["timezone"]) if import_params and "timezone" in import_params - else timezone.utc + else dt_timezone.utc ) tz = timezone.now().astimezone(naive_timezone).tzinfo diff --git a/smartmin/templatetags/smartmin.py b/smartmin/templatetags/smartmin.py index d628718..743f862 100644 --- a/smartmin/templatetags/smartmin.py +++ b/smartmin/templatetags/smartmin.py @@ -1,7 +1,7 @@ import json import re import zoneinfo -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone as dt_timezone from django import template from django.conf import settings @@ -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=dt_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=dt_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=dt_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..6acddf4 100644 --- a/test_runner/blog/tests.py +++ b/test_runner/blog/tests.py @@ -1,5 +1,5 @@ import json -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone as dt_timezone from unittest.mock import patch from zoneinfo import ZoneInfo @@ -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=dt_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=dt_timezone.utc) self.assertEquals("2/1/12", gmail_time(jan_2, now)) def test_user_as_string(self):