Skip to content

Commit

Permalink
handle case where minute can be nil in trip controller time parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ErinLMoore committed Aug 20, 2024
1 parent 12362e6 commit 5ac6692
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apps/concierge_site/lib/param_parsers/param_time.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ defmodule ConciergeSite.ParamParsers.ParamTime do
~T[12:00:00]
iex> ConciergeSite.ParamParsers.ParamTime.to_time(nil)
nil
iex> ConciergeSite.ParamParsers.ParamTime.to_time(%{"am_pm" => "PM", "hour" => "12", "minute" => nil})
~T[12:00:00]
"""
@spec to_time(map) :: Time.t()
def to_time(nil), do: nil

def to_time(form_time) do
hour = hour(form_time["hour"], form_time["am_pm"])
minute = String.to_integer(form_time["minute"])

minute =
if is_binary(form_time["minute"]), do: String.to_integer(form_time["minute"]), else: 0

second = 0

{:ok, time} = Time.from_erl({hour, minute, second})
Expand Down

0 comments on commit 5ac6692

Please sign in to comment.