mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-05 02:41:14 -05:00
Refactor the get_midnight functions to return the date in UTC but for the localised time.
So in June when we are in BST June 16, 00:00 BST => June 15 23:00 UTC
This commit is contained in:
16
app/utils.py
16
app/utils.py
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import pytz
|
||||
from flask import url_for
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE
|
||||
from notifications_utils.template import SMSMessageTemplate, PlainTextEmailTemplate
|
||||
@@ -30,11 +31,18 @@ def get_template_instance(template, values):
|
||||
}[template['template_type']](template, values)
|
||||
|
||||
|
||||
def get_midnight_for_date(date):
|
||||
midnight = datetime.combine(date, datetime.min.time())
|
||||
return midnight
|
||||
def get_london_midnight_in_utc(date):
|
||||
"""
|
||||
This function converts date to midnight as BST (British Standard Time) to UTC,
|
||||
the tzinfo is lastly removed 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-17 23:00:00
|
||||
"""
|
||||
return pytz.timezone('Europe/London').localize(datetime.combine(date, datetime.min.time())).astimezone(
|
||||
pytz.UTC).replace(
|
||||
tzinfo=None)
|
||||
|
||||
|
||||
def get_midnight_for_day_before(date):
|
||||
day_before = date - timedelta(1)
|
||||
return get_midnight_for_date(day_before)
|
||||
return get_london_midnight_in_utc(day_before)
|
||||
|
||||
Reference in New Issue
Block a user