tz utility swap and many test updates

This commit is contained in:
stvnrlly
2022-11-10 12:33:25 -05:00
parent 929b641e2f
commit b50cb4712f
38 changed files with 351 additions and 343 deletions

View File

@@ -1,16 +1,17 @@
from datetime import date, datetime, time, timedelta
from os import getenv
import pytz
from notifications_utils.timezones import convert_bst_to_utc, convert_utc_to_bst
from notifications_utils.timezones import convert_local_timezone_to_utc, convert_utc_to_local_timezone
def get_months_for_financial_year(year):
return [
convert_bst_to_utc(month) for month in (
convert_local_timezone_to_utc(month) for month in (
get_months_for_year(4, 13, year)
+ get_months_for_year(1, 4, year + 1)
)
if convert_bst_to_utc(month) < datetime.now()
if convert_local_timezone_to_utc(month) < datetime.now()
]
@@ -26,8 +27,8 @@ def get_financial_year_dates(year):
year_start_datetime, year_end_datetime = get_financial_year(year)
return (
convert_utc_to_bst(year_start_datetime).date(),
convert_utc_to_bst(year_end_datetime).date()
convert_utc_to_local_timezone(year_start_datetime).date(),
convert_utc_to_local_timezone(year_end_datetime).date()
)
@@ -46,7 +47,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('Europe/London').localize(datetime(year, 4, 1, 0, 0, 0)).astimezone(pytz.UTC).replace(
return pytz.timezone(getenv("TIMEZONE", "America/New_York")).localize(datetime(year, 4, 1, 0, 0, 0)).astimezone(pytz.UTC).replace(
tzinfo=None)
@@ -60,7 +61,7 @@ def get_month_start_and_end_date_in_utc(month_year):
_, num_days = calendar.monthrange(month_year.year, month_year.month)
first_day = datetime(month_year.year, month_year.month, 1, 0, 0, 0)
last_day = datetime(month_year.year, month_year.month, num_days, 23, 59, 59, 99999)
return convert_bst_to_utc(first_day), convert_bst_to_utc(last_day)
return convert_local_timezone_to_utc(first_day), convert_local_timezone_to_utc(last_day)
def get_current_financial_year_start_year():