diff --git a/lib/towerops_web/live/agent_live/helpers.ex b/lib/towerops_web/live/agent_live/helpers.ex index 77dc8513..60b6bbfc 100644 --- a/lib/towerops_web/live/agent_live/helpers.ex +++ b/lib/towerops_web/live/agent_live/helpers.ex @@ -89,4 +89,39 @@ defmodule ToweropsWeb.AgentLive.Helpers do end def format_uptime(_), do: "Unknown" + + @doc """ + Formats a DateTime into a full date and time string. + + Returns strings like "Jan 15, 2026 at 2:34 PM UTC". + """ + def format_datetime(nil), do: "Never" + + def format_datetime(datetime) do + Calendar.strftime(datetime, "%b %d, %Y at %I:%M %p %Z") + end + + @doc """ + Formats a DateTime into a short date string. + + Returns strings like "Jan 15, 2026". + """ + def format_date(nil), do: "Never" + + def format_date(datetime) do + Calendar.strftime(datetime, "%b %d, %Y") + end + + @doc """ + Formats a DateTime into a relative time with full datetime in parentheses. + + Returns strings like "5m ago (Jan 15, 2026 at 2:34 PM UTC)". + """ + def format_last_seen_with_date(nil), do: "Never" + + def format_last_seen_with_date(datetime) do + relative = format_last_seen(datetime) + full = format_datetime(datetime) + "#{relative} (#{full})" + end end diff --git a/lib/towerops_web/live/agent_live/index.html.heex b/lib/towerops_web/live/agent_live/index.html.heex index 1199dee9..83daba3a 100644 --- a/lib/towerops_web/live/agent_live/index.html.heex +++ b/lib/towerops_web/live/agent_live/index.html.heex @@ -98,11 +98,16 @@ <:col :let={agent} label="Last Seen"> -
Last Seen
{format_last_seen(@agent_token.last_seen_at)}
+ <%= if @agent_token.last_seen_at do %> ++ {format_datetime(@agent_token.last_seen_at)} +
+ <% end %> <%= if @agent_token.last_ip do %>{@agent_token.last_ip}
<% end %>