fix view helper dates when nil

This commit is contained in:
shibao 2022-02-15 22:56:49 -05:00
parent d80b80ea22
commit 8e93d632b6

View File

@ -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)}