Some checks reported errors
continuous-integration/drone/push Build was killed
27 lines
614 B
Elixir
27 lines
614 B
Elixir
defmodule MvWeb.Helpers.DateFormatter do
|
|
@moduledoc """
|
|
Centralized date formatting helper for the application.
|
|
Formats dates in European format (dd.mm.yyyy).
|
|
"""
|
|
|
|
use Gettext, backend: MvWeb.Gettext
|
|
|
|
@doc """
|
|
Formats a Date struct to European format (dd.mm.yyyy).
|
|
|
|
## Examples
|
|
|
|
iex> MvWeb.Helpers.DateFormatter.format_date(~D[2024-03-15])
|
|
"15.03.2024"
|
|
|
|
iex> MvWeb.Helpers.DateFormatter.format_date(nil)
|
|
""
|
|
"""
|
|
def format_date(%Date{} = date) do
|
|
Calendar.strftime(date, "%d.%m.%Y")
|
|
end
|
|
|
|
def format_date(nil), do: ""
|
|
|
|
def format_date(_), do: "Invalid date"
|
|
end
|