Skip to content

Commit

Permalink
Use datetime.timezone.utc
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Dec 5, 2023
1 parent e786528 commit 34e2e93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions smartmin/templatetags/smartmin.py
Original file line number Diff line number Diff line change
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=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)
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=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:
Expand All @@ -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)

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=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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 34e2e93

Please sign in to comment.