pull timezone from utils for other pytz instances

This commit is contained in:
stvnrlly
2022-11-16 16:53:55 -05:00
parent e6d30394ba
commit c8533ae524
2 changed files with 5 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import pytz
from notifications_utils.timezones import ( from notifications_utils.timezones import (
convert_local_timezone_to_utc, convert_local_timezone_to_utc,
convert_utc_to_local_timezone, 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 :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: 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) datetime(year, 4, 1, 0, 0, 0)).astimezone(pytz.UTC).replace(tzinfo=None)

View File

@@ -8,13 +8,12 @@ from notifications_utils.template import (
LetterPrintTemplate, LetterPrintTemplate,
SMSMessageTemplate, 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 from sqlalchemy import func
DATETIME_FORMAT_NO_TIMEZONE = "%Y-%m-%d %H:%M:%S.%f" DATETIME_FORMAT_NO_TIMEZONE = "%Y-%m-%d %H:%M:%S.%f"
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ" DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
DATE_FORMAT = "%Y-%m-%d" DATE_FORMAT = "%Y-%m-%d"
local_timezone = pytz.timezone(getenv("TIMEZONE", "America/New_York"))
def pagination_links(pagination, endpoint, **kwargs): 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, 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. 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 :param date: the day to calculate the local midnight in UTC for
:return: the datetime of London midnight in UTC, for example 2016-06-17 = 2016-06-16 23:00:00 :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())) return convert_local_timezone_to_utc(datetime.combine(date, datetime.min.time()))