use local timezone to get future sending options

This commit is contained in:
stvnrlly
2022-11-29 16:38:06 -05:00
parent 8990cc822c
commit 8f47af11da
2 changed files with 16 additions and 16 deletions

View File

@@ -104,25 +104,25 @@ def get_human_day(time, prefix_today_with='T'):
def get_furthest_possible_scheduled_time(): def get_furthest_possible_scheduled_time():
# TODO: update this so it pulls in 4 days at local timezone, not UTC # We want local time to find date boundaries
return (datetime.utcnow() + timedelta(days=4)).replace(hour=0) return (datetime.now(current_app.config['PY_TIMEZONE']) + timedelta(days=4)).replace(hour=0)
def get_next_hours_until(until): 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)) hours = int((until - now).total_seconds() / (60 * 60))
return [ 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) for i in range(1, hours + 1)
] ]
def get_next_days_until(until): 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)) days = int((until - now).total_seconds() / (60 * 60 * 24))
return [ return [
get_human_day( get_human_day(
(now + timedelta(days=i)).replace(tzinfo=pytz.utc), (now + timedelta(days=i)),
prefix_today_with='Later t' prefix_today_with='Later t'
) )
for i in range(0, days + 1) for i in range(0, days + 1)

View File

@@ -4,28 +4,28 @@ from freezegun import freeze_time
from app.main.forms import ChooseTimeForm 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): def test_form_contains_next_24h(notify_admin):
choices = ChooseTimeForm().scheduled_for.choices choices = ChooseTimeForm().scheduled_for.choices
# Friday # Friday
assert choices[0] == ('', 'Now') assert choices[0] == ('', 'Now')
assert choices[1] == ('2016-01-01T17:00:00', 'Today at noon ET') assert choices[1] == ('2016-01-01T12:00:00', 'Today at noon ET')
assert choices[13] == ('2016-01-02T05:00:00', 'Today at midnight ET') assert choices[13] == ('2016-01-02T00:00:00', 'Today at midnight ET')
# Saturday # Saturday
assert choices[14] == ('2016-01-02T06:00:00', 'Tomorrow at 1am ET') assert choices[14] == ('2016-01-02T01:00:00', 'Tomorrow at 1am ET')
assert choices[37] == ('2016-01-03T05:00:00', 'Tomorrow at midnight ET') assert choices[37] == ('2016-01-03T00:00:00', 'Tomorrow at midnight ET')
# Sunday # 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 # Monday
assert choices[62] == ('2016-01-04T06:00:00', 'Monday at 1am ET') assert choices[62] == ('2016-01-04T01:00:00', 'Monday at 1am ET')
assert choices[80] == ('2016-01-05T00:00:00', 'Monday at 7pm ET') assert choices[80] == ('2016-01-04T19:00:00', 'Monday at 7pm ET')
# assert choices[84] == ('2016-01-05T04:00:00', 'Monday at 11pm') assert choices[84] == ('2016-01-04T23:00:00', 'Monday at 11pm ET')
# assert choices[85] == ('2016-01-05T05:00:00', 'Monday at midnight') assert choices[85] == ('2016-01-05T00:00:00', 'Monday at midnight ET')
with pytest.raises(IndexError): with pytest.raises(IndexError):
assert choices[ assert choices[