diff --git a/apps/parse/lib/parse/time.ex b/apps/parse/lib/parse/time.ex index d9c0b49b..e9cdb5f4 100644 --- a/apps/parse/lib/parse/time.ex +++ b/apps/parse/lib/parse/time.ex @@ -14,6 +14,15 @@ defmodule Parse.Time do @spec service_date(DateTime.t()) :: Date.t() def service_date(current_time \\ DateTime.utc_now()) + # Special case for 6/14/26 (6/13 service date after midnight) where service runs late. + # service_date changeover at 5 am, instead of the normal 3 am. + def service_date(%{year: 2026, month: 6, day: 14} = current_time) do + current_unix = DateTime.to_unix(current_time) + back_five_hours = current_unix - 18_000 + {:ok, dt} = FastLocalDatetime.unix_to_datetime(back_five_hours, "America/New_York") + DateTime.to_date(dt) + end + def service_date(%{year: _} = current_time) do current_unix = DateTime.to_unix(current_time) back_three_hours = current_unix - 10_800 diff --git a/apps/parse/test/parse/time_test.exs b/apps/parse/test/parse/time_test.exs index db46a76d..4528514e 100644 --- a/apps/parse/test/parse/time_test.exs +++ b/apps/parse/test/parse/time_test.exs @@ -31,6 +31,20 @@ defmodule Parse.TimeTest do end end + test "returns the previous day until 4:59 am on 6/14/26, but not other dates" do + expected_late_night = ~D[2026-06-13] + + for {time_str, expected_date} <- [ + {"2026-06-14T04:59:59-04:00", ~D[2026-06-13]}, + {"2026-06-14T05:00:00-04:00", ~D[2026-06-14]}, + {"2026-06-15T03:00:00-04:00", ~D[2026-06-15]}, + {"2026-06-13T03:00:00-04:00", ~D[2026-06-13]} + ] do + date_time = Timex.parse!(time_str, "{ISO:Extended}") + assert {time_str, service_date(date_time)} == {time_str, expected_date} + end + end + test "function handles an ambiguous datetime" do expected = ~D[2017-11-04]