summaryrefslogtreecommitdiff
path: root/lib/lsg_web/views/layout_view.ex
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/lsg_web/views/layout_view.ex17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/lsg_web/views/layout_view.ex b/lib/lsg_web/views/layout_view.ex
index 39216ed..956d703 100644
--- a/lib/lsg_web/views/layout_view.ex
+++ b/lib/lsg_web/views/layout_view.ex
@@ -1,3 +1,20 @@
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