17 lines
571 B
Elixir
17 lines
571 B
Elixir
defmodule LabelmakerWeb.LabelsHTML do
|
|
use LabelmakerWeb, :html
|
|
|
|
embed_templates "labels_html/*"
|
|
|
|
def format_size(bytes) when bytes < 1024, do: "#{bytes} B"
|
|
def format_size(bytes) when bytes < 1024 * 1024, do: "#{Float.round(bytes / 1024, 1)} KB"
|
|
def format_size(bytes), do: "#{Float.round(bytes / (1024 * 1024), 1)} MB"
|
|
|
|
def format_datetime({{year, month, day}, {hour, minute, second}}) do
|
|
"#{year}-#{pad(month)}-#{pad(day)} #{pad(hour)}:#{pad(minute)}:#{pad(second)}"
|
|
end
|
|
|
|
defp pad(num) when num < 10, do: "0#{num}"
|
|
defp pad(num), do: "#{num}"
|
|
end
|