4 ms·
Good point! If you're going to pattern match in the initial string then who even needs the second function? def convert("12:" <> <<m::bytes-size(2)>> <> ":
by midgetjones 9y ago
Good point! If you're going to pattern match in the initial string then who even needs the second function?
def convert("12:" <> <<m::bytes-size(2)>> <> ":" <> <<s::bytes-size(2)>> <> "AM") do
"00:#{m}:#{s}"
end
def convert(<<h::bytes-size(2)>> <> ":" <> <<m::bytes-size(2)>> <> ":" <> <<s::bytes-size(2)>> <> "PM") do
h = 12 + String.to_integer(h)
"#{h}:#{m}:#{s}"
end
def convert(<<h::bytes-size(2)>> <> ":" <> <<m::bytes-size(2)>> <> ":" <> <<s::bytes-size(2)>> <> "AM") do
"#{h}:#{m}:#{s}"
end
Whether that's an improvement or not is another matter :)
- ericdouglas 9y agoCrazy stuff! :D I'm wondering how our future-self would feel about such cleverness haha