improve accuracy of timestamps

This commit is contained in:
2025-04-05 03:15:44 +00:00
parent 7096e6abeb
commit da717013de
14 changed files with 87 additions and 42 deletions

View File

@ -89,14 +89,14 @@ defmodule MemexWeb.CoreComponents do
attr :datetime, :any, required: true, doc: "A `DateTime` struct or nil"
@doc """
Phoenix.Component for a <time> element that renders the naivedatetime in the
Phoenix.Component for a <time> element that renders the DateTime in the
user's local timezone
"""
def datetime(assigns)
@spec cast_datetime(NaiveDateTime.t() | nil) :: String.t()
defp cast_datetime(%NaiveDateTime{} = datetime) do
datetime |> DateTime.from_naive!("Etc/UTC") |> DateTime.to_iso8601(:extended)
@spec cast_datetime(DateTime.t() | nil) :: String.t()
defp cast_datetime(%DateTime{} = datetime) do
datetime |> DateTime.to_iso8601(:extended)
end
defp cast_datetime(_datetime), do: ""