fix bug with datetime helpers

This commit is contained in:
shibao 2022-02-15 17:30:58 -05:00
parent 1eda51f1dd
commit a727fa67cf
2 changed files with 29 additions and 7 deletions

View File

@ -19,15 +19,37 @@ defmodule CanneryWeb.ViewHelpers do
~H""" ~H"""
<time <time
datetime={datetime} datetime={@datetime}
x-data={"{ x-data={"{
date: date:
Intl.DateTimeFormat([], {dateStyle: 'short', timeStyle: 'long'}) Intl.DateTimeFormat([], {dateStyle: 'short', timeStyle: 'long'})
.format(new Date(\"#{datetime}\")) .format(new Date(\"#{@datetime}\"))
}"} }"}
x-text="date" x-text="date"
> >
<%= datetime %> <%= @datetime %>
</time>
"""
end
@doc """
Returns a <date> element that renders the Date in the user's local
timezone with Alpine.js
"""
@spec display_date(Date.t()) :: Phoenix.LiveView.Rendered.t()
def display_date(date) do
assigns = %{date: date |> Date.to_iso8601(:extended)}
~H"""
<time
datetime={@date}
x-data={"{
date:
Intl.DateTimeFormat([], {timeZone: 'Etc/UTC', dateStyle: 'short'}).format(new Date(\"#{@date}\"))
}"}
x-text="date"
>
<%= @date %>
</time> </time>
""" """
end end