Consolidate duration formatting
This commit is contained in:
@@ -2,6 +2,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.Show do
|
||||
use MusicLibraryWeb, :live_view
|
||||
|
||||
alias MusicLibrary.ScrobbleActivity
|
||||
alias MusicLibraryWeb.Duration
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
@@ -78,14 +79,4 @@ defmodule MusicLibraryWeb.ScrobbleLive.Show do
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
||||
defp format_duration(nil), do: "Unknown"
|
||||
|
||||
defp format_duration(milliseconds) when is_integer(milliseconds) do
|
||||
seconds = div(milliseconds, 1000)
|
||||
minutes = div(seconds, 60)
|
||||
remaining_seconds = rem(seconds, 60)
|
||||
|
||||
"#{minutes}:#{String.pad_leading(Integer.to_string(remaining_seconds), 2, "0")}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -143,7 +143,7 @@
|
||||
:if={track.length}
|
||||
class="text-xs text-gray-500 dark:text-gray-400 font-mono"
|
||||
>
|
||||
{format_duration(track.length)}
|
||||
{Duration.format_duration(track.length)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user