forked from shibao/cannery
fix view helper dates when nil
This commit is contained in:
parent
d80b80ea22
commit
8e93d632b6
@ -11,7 +11,8 @@ defmodule CanneryWeb.ViewHelpers do
|
||||
Returns a <time> element that renders the naivedatetime in the user's local
|
||||
timezone with Alpine.js
|
||||
"""
|
||||
@spec display_datetime(NaiveDateTime.t()) :: Phoenix.LiveView.Rendered.t()
|
||||
@spec display_datetime(NaiveDateTime.t() | nil) :: Phoenix.LiveView.Rendered.t()
|
||||
def display_datetime(nil), do: ""
|
||||
def display_datetime(datetime) do
|
||||
assigns = %{
|
||||
datetime: datetime |> DateTime.from_naive!("Etc/UTC") |> DateTime.to_iso8601(:extended)
|
||||
@ -36,7 +37,8 @@ defmodule CanneryWeb.ViewHelpers do
|
||||
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()
|
||||
@spec display_date(Date.t() | nil) :: Phoenix.LiveView.Rendered.t()
|
||||
def display_date(nil), do: ""
|
||||
def display_date(date) do
|
||||
assigns = %{date: date |> Date.to_iso8601(:extended)}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user