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"
>
<%= live_patch to: @return_to,
id: "close",
class:
"absolute top-8 right-10 text-gray-500 hover:text-gray-800 transition-all duration-500 ease-in-out",
phx_click: hide_modal() do %>
id: "close",
class:
"absolute top-8 right-10 text-gray-500 hover:text-gray-800 transition-all duration-500 ease-in-out",
phx_click: hide_modal() do %>
<i class="fa-fw fa-lg fas fa-times"></i>
<% end %>

View File

@ -19,15 +19,37 @@ defmodule CanneryWeb.ViewHelpers do
~H"""
<time
datetime={datetime}
datetime={@datetime}
x-data={"{
date:
Intl.DateTimeFormat([], {dateStyle: 'short', timeStyle: 'long'})
.format(new Date(\"#{datetime}\"))
.format(new Date(\"#{@datetime}\"))
}"}
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>
"""
end