Skip to content

Commit

Permalink
hotfix(Schedules.HoursOfOperation): don't break if schedule has no times
Browse files Browse the repository at this point in the history
  • Loading branch information
thecristen committed Oct 5, 2023
1 parent 2cd9658 commit c11e9a0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apps/schedules/lib/hours_of_operation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ defmodule Schedules.HoursOfOperation do

{min, max} =
x
|> Stream.reject(&no_times?(&1.attributes))
|> Stream.map(&Timex.parse!(time(&1.attributes), "{ISO:Extended}"))
|> Enum.min_max_by(&DateTime.to_unix(&1, :nanosecond))

Expand All @@ -444,6 +445,7 @@ defmodule Schedules.HoursOfOperation do
defp departure(data, _headsigns, _description) do
{min, max} =
data
|> Stream.reject(&no_times?(&1.attributes))
|> Stream.map(&Timex.parse!(time(&1.attributes), "{ISO:Extended}"))
|> Enum.min_max_by(&DateTime.to_unix(&1, :nanosecond))

Expand All @@ -452,4 +454,12 @@ defmodule Schedules.HoursOfOperation do
last_departure: max
}
end

defp no_times?(%{
"arrival_time" => nil,
"departure_time" => nil
}),
do: true

defp no_times?(_), do: false
end

0 comments on commit c11e9a0

Please sign in to comment.