Skip to content

Commit

Permalink
Use django utils timezone.timezone.utc
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Dec 5, 2023
1 parent 6d8fdc4 commit cad277d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions smartmin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import traceback
import zoneinfo
from datetime import datetime, timezone as dt_timezone
from datetime import datetime

from xlrd import XL_CELL_DATE, XLRDError, open_workbook, xldate_as_tuple

Expand Down Expand Up @@ -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 dt_timezone.utc
else timezone.timezone.utc
)
tz = timezone.now().astimezone(naive_timezone).tzinfo

Expand Down
8 changes: 4 additions & 4 deletions smartmin/templatetags/smartmin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import re
import zoneinfo
from datetime import datetime, timedelta, timezone as dt_timezone
from datetime import datetime, timedelta

from django import template
from django.conf import settings
Expand Down Expand Up @@ -34,7 +34,7 @@ def format_datetime(time):
"""
user_time_zone = timezone.get_current_timezone()
if time.tzinfo is None:
time = time.replace(tzinfo=dt_timezone.utc)
time = time.replace(tzinfo=timezone.timezone.utc)
user_time_zone = zoneinfo.ZoneInfo(getattr(settings, "USER_TIME_ZONE", "GMT"))

time = time.astimezone(user_time_zone)
Expand Down Expand Up @@ -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=dt_timezone.utc)
dtime = dtime.replace(tzinfo=timezone.timezone.utc)
user_time_zone = zoneinfo.ZoneInfo(getattr(settings, "USER_TIME_ZONE", "GMT"))
dtime = dtime.astimezone(user_time_zone)
else:
Expand All @@ -174,7 +174,7 @@ def gmail_time(dtime, now=None):
now = timezone.now()

if now.tzinfo is None:
now = now.replace(tzinfo=dt_timezone.utc)
now = now.replace(tzinfo=timezone.timezone.utc)

twelve_hours_ago = now - timedelta(hours=12)

Expand Down
4 changes: 2 additions & 2 deletions test_runner/blog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=dt_timezone.utc).astimezone(ZoneInfo("Africa/Kigali"))
local_created = self.post.created_on.replace(tzinfo=timezone.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):
Expand Down Expand Up @@ -1183,7 +1183,7 @@ def test_gmail_time(self):
self.assertEqual(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=dt_timezone.utc)
jan_2 = datetime(2012, 1, 2, 17, 5, 0, 0).replace(tzinfo=timezone.timezone.utc)
self.assertEquals("2/1/12", gmail_time(jan_2, now))

def test_user_as_string(self):
Expand Down

0 comments on commit cad277d

Please sign in to comment.