Show dates in european format
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
ee414c9440
commit
e6c5a58c65
6 changed files with 54 additions and 11 deletions
27
lib/mv_web/helpers/date_formatter.ex
Normal file
27
lib/mv_web/helpers/date_formatter.ex
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue