Skip to content

Commit

Permalink
Use datetime timezone aliased as tzone
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Mar 22, 2024
1 parent c58f34a commit b11bfbb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ureport/backend/rapidpro.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
import time
from collections import defaultdict
from datetime import timedelta
from datetime import timedelta, timezone as tzone

import requests
from django_redis import get_redis_connection
Expand Down Expand Up @@ -638,7 +638,7 @@ def pull_results(self, poll, modified_after, modified_before, progress_callback=
latest_synced_obj_time
):
latest_synced_obj_time = datetime_to_json_date(
temba_run.modified_on.replace(tzinfo=timezone.utc)
temba_run.modified_on.replace(tzinfo=tzone.utc)
)

contact_obj = contacts_map.get(temba_run.contact.uuid, None)
Expand Down
4 changes: 2 additions & 2 deletions ureport/polls/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import uuid
from collections import defaultdict
from datetime import timedelta
from datetime import timedelta, timezone as tzone

import six
from django_redis import get_redis_connection
Expand Down Expand Up @@ -317,7 +317,7 @@ def pull_refresh_task(self):
now = timezone.now()
cache.set(
Poll.POLL_PULL_ALL_RESULTS_AFTER_DELETE_FLAG % (self.org_id, self.pk),
datetime_to_json_date(now.replace(tzinfo=timezone.utc)),
datetime_to_json_date(now.replace(tzinfo=tzone.utc)),
None,
)

Expand Down
6 changes: 3 additions & 3 deletions ureport/polls/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import uuid
import zoneinfo
from datetime import date, datetime, timedelta
from datetime import date, datetime, timedelta, timezone as tzone

import six
from mock import Mock, patch
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_pull_refresh_task(self, mock_cache_set, mock_pull_refresh):
now = timezone.now()
mock_cache_set.assert_called_once_with(
Poll.POLL_PULL_ALL_RESULTS_AFTER_DELETE_FLAG % (poll1.org_id, poll1.pk),
datetime_to_json_date(now.replace(tzinfo=timezone.utc)),
datetime_to_json_date(now.replace(tzinfo=tzone.utc)),
None,
)

Expand Down Expand Up @@ -663,7 +663,7 @@ def test_poll_poll_date_view(self):
self.assertEqual(poll.org, self.uganda)
self.assertEqual(poll.title, "Poll 1")
self.assertEqual(
poll.poll_date.astimezone(self.uganda.timezone).replace(tzinfo=timezone.utc),
poll.poll_date.astimezone(self.uganda.timezone).replace(tzinfo=tzone.utc),
yesterday.replace(microsecond=0),
)

Expand Down
4 changes: 2 additions & 2 deletions ureport/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import zoneinfo
from collections import defaultdict
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone as tzone
from itertools import chain, islice

import iso8601
Expand Down Expand Up @@ -57,7 +57,7 @@ def datetime_to_json_date(dt):
Formats a datetime as a string for inclusion in JSON
"""
# always output as UTC / Z and always include milliseconds
as_utc = dt.astimezone(timezone.utc)
as_utc = dt.astimezone(tzone.utc)
return as_utc.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"


Expand Down
4 changes: 2 additions & 2 deletions ureport/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import json
import zoneinfo
from datetime import datetime
from datetime import datetime, timezone as tzone

import mock
import redis
Expand Down Expand Up @@ -58,7 +58,7 @@ def clear_cache(self):
r.flushdb()

def test_datetime_to_json_date(self):
d1 = datetime(2014, 1, 2, 3, 4, 5, tzinfo=timezone.utc)
d1 = datetime(2014, 1, 2, 3, 4, 5, tzinfo=tzone.utc)
self.assertEqual(datetime_to_json_date(d1), "2014-01-02T03:04:05.000Z")
self.assertEqual(json_date_to_datetime("2014-01-02T03:04:05.000+00:00"), d1)
self.assertEqual(json_date_to_datetime("2014-01-02T03:04:05.000Z"), d1)
Expand Down

0 comments on commit b11bfbb

Please sign in to comment.