Locale-aware date formatting.
Provides centralized date formatting that replaces %B and %b format
directives with translated month names from YAML translation files.
The format string is resolved in this order:
- Per-language
date_formatoverride in site config date_formatkey from YAML translations for the language- Default
"%b %-d, %Y"(English style)
Examples
iex> Sayfa.DateFormat.format(~D[2024-02-15], :en)
"Feb 15, 2024"
Summary
Functions
Formats a date using locale-aware month names.
Functions
@spec format( Date.t() | DateTime.t() | NaiveDateTime.t() | String.t() | nil, atom(), map() ) :: String.t()
Formats a date using locale-aware month names.
Returns "" when date is nil.
Accepts %Date{}, %DateTime{}, %NaiveDateTime{}, or an ISO 8601 string.
DateTime and NaiveDateTime values are converted to their date component.
String values are parsed via Date.from_iso8601/1; if unparseable, the
original string is returned as-is.
Examples
iex> Sayfa.DateFormat.format(~D[2024-01-15], :en)
"Jan 15, 2024"
iex> Sayfa.DateFormat.format(nil, :en)
""
iex> Sayfa.DateFormat.format(~U[2024-01-15 10:00:00Z], :en)
"Jan 15, 2024"
iex> Sayfa.DateFormat.format(~N[2024-01-15 10:00:00], :en)
"Jan 15, 2024"
iex> Sayfa.DateFormat.format("2024-01-15", :en)
"Jan 15, 2024"