From c8533ae5245466a6720c194eba62646ddd898679 Mon Sep 17 00:00:00 2001 From: stvnrlly Date: Wed, 16 Nov 2022 16:53:55 -0500 Subject: [PATCH] pull timezone from utils for other pytz instances --- app/dao/date_util.py | 3 ++- app/utils.py | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/dao/date_util.py b/app/dao/date_util.py index f6a7252f7..08fa4186a 100644 --- a/app/dao/date_util.py +++ b/app/dao/date_util.py @@ -5,6 +5,7 @@ import pytz from notifications_utils.timezones import ( convert_local_timezone_to_utc, convert_utc_to_local_timezone, + local_timezone ) @@ -50,7 +51,7 @@ def get_april_fools(year): :param year: the year to calculate the April 1, 00:00 BST for :return: the datetime of April 1 for the given year, for example 2016 = 2016-03-31 23:00:00 """ - return pytz.timezone(getenv("TIMEZONE", "America/New_York")).localize( + return local_timezone.localize( datetime(year, 4, 1, 0, 0, 0)).astimezone(pytz.UTC).replace(tzinfo=None) diff --git a/app/utils.py b/app/utils.py index 731c17cd0..c483cbe76 100644 --- a/app/utils.py +++ b/app/utils.py @@ -8,13 +8,12 @@ from notifications_utils.template import ( LetterPrintTemplate, SMSMessageTemplate, ) -from notifications_utils.timezones import convert_local_timezone_to_utc +from notifications_utils.timezones import convert_local_timezone_to_utc, local_timezone from sqlalchemy import func DATETIME_FORMAT_NO_TIMEZONE = "%Y-%m-%d %H:%M:%S.%f" DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ" DATE_FORMAT = "%Y-%m-%d" -local_timezone = pytz.timezone(getenv("TIMEZONE", "America/New_York")) def pagination_links(pagination, endpoint, **kwargs): @@ -60,8 +59,8 @@ def get_local_midnight_in_utc(date): """ This function converts date from midnight in local time to UTC, removing the tzinfo from the datetime because the database stores the timestamps without timezone. - :param date: the day to calculate the London midnight in UTC for - :return: the datetime of London midnight in UTC, for example 2016-06-17 = 2016-06-16 23:00:00 + :param date: the day to calculate the local midnight in UTC for + :return: the datetime of local midnight in UTC, for example 2016-06-17 = 2016-06-16 23:00:00 """ return convert_local_timezone_to_utc(datetime.combine(date, datetime.min.time()))