| 12345678910111213141516171819202122232425262728293031323334353637 |
- defmodule CvGenView.Date do
- use Phoenix.Component
- attr(:date, :any)
- attr(:rest, :global)
- def date(assigns) do
- ~H"""
- <time datetime={@date} {@rest}><%= localized(@date) %></time>
- """
- end
- defp localized(nil), do: "Aujourd'hui"
- defp localized(date) when is_binary(date) do
- case String.split(date, "-") do
- [year, month] ->
- {year, month} = {String.to_integer(year), String.to_integer(month)}
- Date.new!(year, month, 1) |> localized()
- [year] ->
- year
- end
- end
- defp localized(date) when is_struct(date, Date),
- do:
- Calendar.strftime(
- date,
- "%B %Y",
- month_names: fn month ->
- {"Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre",
- "Octobre", "Novembre", "Décembre"}
- |> elem(month - 1)
- end
- )
- end
|