I'm trying to make use of the code in this blog post: [Phoenix LiveView] formatting date/time with local time zone.
I confirmed (with IO.inspect
) that his mount
and defp
code I added to a LiveView adds the socket assigns. But he doesn't give an example of how to call the format_time
function from a heex template. Perhaps it should be obvious, but it's not obvious to me. I tried this:
<%= if connected?(@socket) do
Cldr.format_time(@auction.started_or_paused_at,
locale: @socket.assigns.locale,
timezone: @socket.assigns.timezone)
else
Cldr.format_time(@auction.started_or_paused_at)
end
%>
But I get this error:
[error] GenServer #PID<0.655.0> terminating
** (KeyError) key :locale not found in: #Phoenix.LiveView.Socket.AssignsNotInSocket<>
(ssauction_live 0.1.0) lib/ssauction_live_web/live/auction_live/show.html.heex:32: anonymous fn/2 in SSAuctionWeb.AuctionLive.Show.render/1
...
I guess I can't use the socket assigns while rendering?