Standardise how we query midnight-to-midnight

Partially addresses [1] (lots more detail to read in the comment).
I've also added some tests for the status DAO function to confirm
it behaves as expected across timezones.

[1]: https://github.com/alphagov/notifications-api/pull/3437#discussion_r802634913
This commit is contained in:
Ben Thorner
2022-02-09 17:44:00 +00:00
parent 7f4b140f97
commit 6e8f121548
4 changed files with 30 additions and 12 deletions

View File

@@ -8,7 +8,7 @@ from notifications_utils.template import (
LetterPrintTemplate,
SMSMessageTemplate,
)
from notifications_utils.timezones import convert_utc_to_bst
from notifications_utils.timezones import convert_bst_to_utc, convert_utc_to_bst
from sqlalchemy import func
DATETIME_FORMAT_NO_TIMEZONE = "%Y-%m-%d %H:%M:%S.%f"
@@ -64,9 +64,7 @@ def get_london_midnight_in_utc(date):
: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
"""
return local_timezone.localize(datetime.combine(date, datetime.min.time())).astimezone(
pytz.UTC).replace(
tzinfo=None)
return convert_bst_to_utc(datetime.combine(date, datetime.min.time()))
def get_midnight_for_day_before(date):