make ChooseTimeForm time zone aware

This commit is contained in:
Kenneth Kehl
2024-02-07 12:14:00 -08:00
parent ad34ca0a11
commit 330fad469e
2 changed files with 10 additions and 10 deletions

View File

@@ -70,7 +70,7 @@ from app.utils.user_permissions import all_ui_permissions, permission_options
def get_time_value_and_label(future_time): def get_time_value_and_label(future_time):
preferred_tz = pytz.timezone(get_user_preferred_timezone()) preferred_tz = pytz.timezone(get_user_preferred_timezone())
return ( return (
future_time.astimezone(preferred_tz).replace(tzinfo=None).isoformat(), future_time.astimezone(preferred_tz).isoformat(),
"{} at {} {}".format( "{} at {} {}".format(
get_human_day(future_time.astimezone(preferred_tz)), get_human_day(future_time.astimezone(preferred_tz)),
get_human_time(future_time.astimezone(preferred_tz)), get_human_time(future_time.astimezone(preferred_tz)),

View File

@@ -10,21 +10,21 @@ def test_form_contains_next_24h(notify_admin):
# Friday # Friday
assert choices[0] == ("", "Now") assert choices[0] == ("", "Now")
assert choices[1] == ("2016-01-01T07:00:00", "Today at 7am US/Eastern") assert choices[1] == ("2016-01-01T07:00:00-05:00", "Today at 7am US/Eastern")
assert choices[13] == ("2016-01-01T19:00:00", "Today at 7pm US/Eastern") assert choices[13] == ("2016-01-01T19:00:00-05:00", "Today at 7pm US/Eastern")
# Saturday # Saturday
assert choices[14] == ("2016-01-01T20:00:00", "Today at 8pm US/Eastern") assert choices[14] == ("2016-01-01T20:00:00-05:00", "Today at 8pm US/Eastern")
assert choices[37] == ("2016-01-02T19:00:00", "Tomorrow at 7pm US/Eastern") assert choices[37] == ("2016-01-02T19:00:00-05:00", "Tomorrow at 7pm US/Eastern")
# Sunday # Sunday
assert choices[38] == ("2016-01-02T20:00:00", "Tomorrow at 8pm US/Eastern") assert choices[38] == ("2016-01-02T20:00:00-05:00", "Tomorrow at 8pm US/Eastern")
# Monday # Monday
assert choices[62] == ("2016-01-03T20:00:00", "Sunday at 8pm US/Eastern") assert choices[62] == ("2016-01-03T20:00:00-05:00", "Sunday at 8pm US/Eastern")
assert choices[80] == ("2016-01-04T14:00:00", "Monday at 2pm US/Eastern") assert choices[80] == ("2016-01-04T14:00:00-05:00", "Monday at 2pm US/Eastern")
assert choices[84] == ("2016-01-04T18:00:00", "Monday at 6pm US/Eastern") assert choices[84] == ("2016-01-04T18:00:00-05:00", "Monday at 6pm US/Eastern")
assert choices[85] == ("2016-01-04T19:00:00", "Monday at 7pm US/Eastern") assert choices[85] == ("2016-01-04T19:00:00-05:00", "Monday at 7pm US/Eastern")
with pytest.raises(IndexError): with pytest.raises(IndexError):
assert choices[ assert choices[