mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-05 08:40:29 -04:00
notify-260 remove server-side timezone handling
This commit is contained in:
@@ -1,20 +1,13 @@
|
||||
from datetime import date, datetime, time, timedelta
|
||||
|
||||
import pytz
|
||||
from notifications_utils.timezones import (
|
||||
convert_local_timezone_to_utc,
|
||||
convert_utc_to_local_timezone,
|
||||
local_timezone,
|
||||
)
|
||||
|
||||
|
||||
def get_months_for_financial_year(year):
|
||||
return [
|
||||
convert_local_timezone_to_utc(month) for month in (
|
||||
month for month in (
|
||||
get_months_for_year(4, 13, year)
|
||||
+ get_months_for_year(1, 4, year + 1)
|
||||
)
|
||||
if convert_local_timezone_to_utc(month) < datetime.now()
|
||||
if month < datetime.now()
|
||||
]
|
||||
|
||||
|
||||
@@ -30,8 +23,8 @@ def get_financial_year_dates(year):
|
||||
year_start_datetime, year_end_datetime = get_financial_year(year)
|
||||
|
||||
return (
|
||||
convert_utc_to_local_timezone(year_start_datetime).date(),
|
||||
convert_utc_to_local_timezone(year_end_datetime).date()
|
||||
year_start_datetime.date(),
|
||||
year_end_datetime.date()
|
||||
)
|
||||
|
||||
|
||||
@@ -44,14 +37,7 @@ def get_current_financial_year():
|
||||
|
||||
|
||||
def get_april_fools(year):
|
||||
"""
|
||||
This function converts the start of the financial year April 1, 00:00 as BST (British Standard Time) to UTC,
|
||||
the tzinfo is lastly removed from the datetime because the database stores the timestamps without timezone.
|
||||
: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 local_timezone.localize(
|
||||
datetime(year, 4, 1, 0, 0, 0)).astimezone(pytz.UTC).replace(tzinfo=None)
|
||||
return datetime(year, 4, 1, 0, 0, 0)
|
||||
|
||||
|
||||
def get_month_start_and_end_date_in_utc(month_year):
|
||||
@@ -64,7 +50,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_local_timezone_to_utc(first_day), convert_local_timezone_to_utc(last_day)
|
||||
return first_day, last_day
|
||||
|
||||
|
||||
def get_current_financial_year_start_year():
|
||||
|
||||
Reference in New Issue
Block a user