Skip to content

Instantly share code, notes, and snippets.

@hauleth
Created February 2, 2020 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hauleth/e8acd84a319b11946f1a687bcaf50639 to your computer and use it in GitHub Desktop.
Save hauleth/e8acd84a319b11946f1a687bcaf50639 to your computer and use it in GitHub Desktop.
defmodule TimeFormat do
def format(seconds) do
seconds
|> :calendar.seconds_to_time()
|> do_format()
|> to_string()
end
defp do_format({0, m, s}), do: :io_lib.format("~B:~2..0B", [m, s])
defp do_format({h, m, s}), do: :io_lib.format("~B:~2..0B:~2..0B", [h, m, s])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment