Skip to content

Commit

Permalink
remove nested if expression
Browse files Browse the repository at this point in the history
  • Loading branch information
sloanelybutsurely committed May 16, 2024
1 parent c525734 commit c9a9dd9
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/screens/v2/widget_instance/line_map.ex
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,17 @@ defmodule Screens.V2.WidgetInstance.LineMap do
&match?(%Departure{prediction: %Prediction{trip: %Trip{direction_id: ^direction_id}}}, &1)
)

if prediction_count < 2 do
if (departure = Enum.find(departures, &is_nil(&1.prediction))) && prediction_count < 2 do
%{name: origin_stop_name} = Enum.at(stops, 0)

if departure = Enum.find(departures, &is_nil(&1.prediction)) do
{:ok, local_time} =
departure
|> Departure.time()
|> DateTime.shift_zone("America/New_York")
{:ok, local_time} =
departure
|> Departure.time()
|> DateTime.shift_zone("America/New_York")

{:ok, timestamp} = Timex.format(local_time, "{h12}:{m}")
{:ok, timestamp} = Timex.format(local_time, "{h12}:{m}")

%{timestamp: timestamp, station_name: origin_stop_name}
else
nil
end
else
nil
%{timestamp: timestamp, station_name: origin_stop_name}
end
end
end

0 comments on commit c9a9dd9

Please sign in to comment.