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

@ -56,10 +56,10 @@ defmodule CanneryWeb.LiveHelpers do
phx-key="escape" phx-key="escape"
> >
<%= live_patch to: @return_to, <%= live_patch to: @return_to,
id: "close", id: "close",
class: class:
"absolute top-8 right-10 text-gray-500 hover:text-gray-800 transition-all duration-500 ease-in-out", "absolute top-8 right-10 text-gray-500 hover:text-gray-800 transition-all duration-500 ease-in-out",
phx_click: hide_modal() do %> phx_click: hide_modal() do %>
<i class="fa-fw fa-lg fas fa-times"></i> <i class="fa-fw fa-lg fas fa-times"></i>
<% end %> <% end %>

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