From 8f47af11dafa4b6ae76b3b100434c319b085d02f Mon Sep 17 00:00:00 2001 From: stvnrlly Date: Tue, 29 Nov 2022 16:38:06 -0500 Subject: [PATCH] use local timezone to get future sending options --- app/main/forms.py | 12 +++++------ tests/app/main/forms/test_choose_time_form.py | 20 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index a8b7f9f33..8452be2ad 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -104,25 +104,25 @@ def get_human_day(time, prefix_today_with='T'): def get_furthest_possible_scheduled_time(): - # TODO: update this so it pulls in 4 days at local timezone, not UTC - return (datetime.utcnow() + timedelta(days=4)).replace(hour=0) + # We want local time to find date boundaries + return (datetime.now(current_app.config['PY_TIMEZONE']) + timedelta(days=4)).replace(hour=0) def get_next_hours_until(until): - now = datetime.utcnow() + now = datetime.now(current_app.config['PY_TIMEZONE']) hours = int((until - now).total_seconds() / (60 * 60)) return [ - (now + timedelta(hours=i)).replace(minute=0, second=0, microsecond=0).replace(tzinfo=pytz.utc) + (now + timedelta(hours=i)).replace(minute=0, second=0, microsecond=0) for i in range(1, hours + 1) ] def get_next_days_until(until): - now = datetime.utcnow() + now = datetime.now(current_app.config['PY_TIMEZONE']) days = int((until - now).total_seconds() / (60 * 60 * 24)) return [ get_human_day( - (now + timedelta(days=i)).replace(tzinfo=pytz.utc), + (now + timedelta(days=i)), prefix_today_with='Later t' ) for i in range(0, days + 1) diff --git a/tests/app/main/forms/test_choose_time_form.py b/tests/app/main/forms/test_choose_time_form.py index e419f54c7..c1c0b409c 100644 --- a/tests/app/main/forms/test_choose_time_form.py +++ b/tests/app/main/forms/test_choose_time_form.py @@ -4,28 +4,28 @@ from freezegun import freeze_time from app.main.forms import ChooseTimeForm -@freeze_time("2016-01-01 16:09:00.061258") # this is during DST +@freeze_time("2016-01-01 16:09:00.061258") def test_form_contains_next_24h(notify_admin): choices = ChooseTimeForm().scheduled_for.choices # Friday assert choices[0] == ('', 'Now') - assert choices[1] == ('2016-01-01T17:00:00', 'Today at noon ET') - assert choices[13] == ('2016-01-02T05:00:00', 'Today at midnight ET') + assert choices[1] == ('2016-01-01T12:00:00', 'Today at noon ET') + assert choices[13] == ('2016-01-02T00:00:00', 'Today at midnight ET') # Saturday - assert choices[14] == ('2016-01-02T06:00:00', 'Tomorrow at 1am ET') - assert choices[37] == ('2016-01-03T05:00:00', 'Tomorrow at midnight ET') + assert choices[14] == ('2016-01-02T01:00:00', 'Tomorrow at 1am ET') + assert choices[37] == ('2016-01-03T00:00:00', 'Tomorrow at midnight ET') # Sunday - assert choices[38] == ('2016-01-03T06:00:00', 'Sunday at 1am ET') + assert choices[38] == ('2016-01-03T01:00:00', 'Sunday at 1am ET') # Monday - assert choices[62] == ('2016-01-04T06:00:00', 'Monday at 1am ET') - assert choices[80] == ('2016-01-05T00:00:00', 'Monday at 7pm ET') - # assert choices[84] == ('2016-01-05T04:00:00', 'Monday at 11pm') - # assert choices[85] == ('2016-01-05T05:00:00', 'Monday at midnight') + assert choices[62] == ('2016-01-04T01:00:00', 'Monday at 1am ET') + assert choices[80] == ('2016-01-04T19:00:00', 'Monday at 7pm ET') + assert choices[84] == ('2016-01-04T23:00:00', 'Monday at 11pm ET') + assert choices[85] == ('2016-01-05T00:00:00', 'Monday at midnight ET') with pytest.raises(IndexError): assert choices[