defmodule LSGWeb.LayoutView do use LSGWeb, :view def format_time(date, with_relative \\ true) do alias Timex.Format.DateTime.Formatters alias Timex.Timezone date = if is_integer(date) do date |> DateTime.from_unix!(:millisecond) |> Timezone.convert("Europe/Paris") else date end {:ok, relative} = Formatters.Relative.relative_to(date, Timex.now("Europe/Paris"), "{relative}", "fr") {:ok, detail} = Formatters.Default.lformat(date, "{D}/{M}/{YYYY} {h24}:{m}", "fr") content_tag(:time, if(with_relative, do: relative, else: detail), [title: detail]) end end