diff --git a/app/celery/reporting_tasks.py b/app/celery/reporting_tasks.py index d8aaa3ef3..7d5ca33f5 100644 --- a/app/celery/reporting_tasks.py +++ b/app/celery/reporting_tasks.py @@ -2,6 +2,7 @@ from datetime import datetime, timedelta from flask import current_app from notifications_utils.statsd_decorators import statsd +from notifications_utils.timezones import convert_utc_to_bst from app import notify_celery from app.cronitor import cronitor @@ -10,7 +11,6 @@ from app.dao.fact_billing_dao import ( update_fact_billing ) from app.dao.fact_notification_status_dao import fetch_notification_status_for_day, update_fact_notification_status -from app.utils import convert_utc_to_bst @notify_celery.task(name="create-nightly-billing") diff --git a/app/utils.py b/app/utils.py index fcd33b54b..dfdd573d1 100644 --- a/app/utils.py +++ b/app/utils.py @@ -4,7 +4,6 @@ import pytz from flask import url_for from sqlalchemy import func from notifications_utils.template import SMSMessageTemplate, WithSubjectTemplate, get_html_email_body -from notifications_utils.timezones import convert_utc_to_bst local_timezone = pytz.timezone("Europe/London") @@ -100,21 +99,6 @@ def midnight_n_days_ago(number_of_days): return get_london_midnight_in_utc(datetime.utcnow() - timedelta(days=number_of_days)) -def last_n_days(limit_days): - """ - Returns the last n dates, oldest first. Takes care of daylight savings (but returns a date, be careful how you - manipulate it later! Don't directly use the date for comparing to UTC datetimes!). Includes today. - """ - return [ - datetime.combine( - (convert_utc_to_bst(datetime.utcnow()) - timedelta(days=x)), - datetime.min.time() - ) - # reverse the countdown, -1 from first two args to ensure it stays 0-indexed - for x in range(limit_days - 1, -1, -1) - ] - - def escape_special_characters(string): for special_character in ('\\', '_', '%', '/'): string = string.replace( diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index 04d710af3..6978085ab 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -7,7 +7,6 @@ from app.utils import ( get_london_midnight_in_utc, get_midnight_for_day_before, midnight_n_days_ago, - last_n_days ) @@ -52,21 +51,3 @@ def test_get_midnight_for_day_before_returns_expected_date(date, expected_date): def test_midnight_n_days_ago(current_time, arg, expected_datetime): with freeze_time(current_time): assert midnight_n_days_ago(arg) == expected_datetime - - -def test_last_n_days(): - with freeze_time('2018-03-27 12:00'): - res = last_n_days(5) - - assert res == [ - datetime(2018, 3, 23, 0, 0), - datetime(2018, 3, 24, 0, 0), - datetime(2018, 3, 25, 0, 0), - datetime(2018, 3, 26, 0, 0), - datetime(2018, 3, 27, 0, 0) - ] - - -@pytest.mark.parametrize('arg', [0, -1]) -def test_last_n_days_invalid_arg(arg): - assert last_n_days(arg) == []