diff --git a/ureport/backend/rapidpro.py b/ureport/backend/rapidpro.py index 12362994f..3990b72a0 100644 --- a/ureport/backend/rapidpro.py +++ b/ureport/backend/rapidpro.py @@ -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 @@ -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) diff --git a/ureport/polls/models.py b/ureport/polls/models.py index 5faf00fd6..645bc25ed 100644 --- a/ureport/polls/models.py +++ b/ureport/polls/models.py @@ -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 @@ -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, ) diff --git a/ureport/polls/tests.py b/ureport/polls/tests.py index ed389df08..73825aa15 100644 --- a/ureport/polls/tests.py +++ b/ureport/polls/tests.py @@ -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 @@ -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, ) @@ -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), ) diff --git a/ureport/utils/__init__.py b/ureport/utils/__init__.py index 6abd9d12a..9176d2d25 100644 --- a/ureport/utils/__init__.py +++ b/ureport/utils/__init__.py @@ -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 @@ -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" diff --git a/ureport/utils/tests.py b/ureport/utils/tests.py index 43099773d..5dae118e5 100644 --- a/ureport/utils/tests.py +++ b/ureport/utils/tests.py @@ -3,7 +3,7 @@ import json import zoneinfo -from datetime import datetime +from datetime import datetime, timezone as tzone import mock import redis @@ -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)