add time ago on info page

This commit is contained in:
Graham McIntire 2025-07-07 10:01:14 -05:00
parent feb71c73d9
commit 280461f281
No known key found for this signature in database
2 changed files with 55 additions and 4 deletions

View file

@ -124,7 +124,7 @@ defmodule AprsmeWeb.InfoLive.Show do
callsign: p.sender,
distance: format_distance(dist),
course: course,
last_heard: PacketUtils.get_timestamp(p),
last_heard: format_timestamp_for_display(p),
packet: p
}
end)
@ -182,6 +182,39 @@ defmodule AprsmeWeb.InfoLive.Show do
defp to_float(_), do: 0.0
defp format_timestamp_for_display(packet) do
received_at = get_received_at(packet)
if received_at do
timestamp_dt = AprsmeWeb.TimeHelpers.to_datetime(received_at)
if timestamp_dt do
%{
time_ago: AprsmeWeb.TimeHelpers.time_ago_in_words(timestamp_dt),
formatted: Calendar.strftime(timestamp_dt, "%Y-%m-%d %H:%M:%S UTC")
}
else
%{
time_ago: gettext("Unknown"),
formatted: ""
}
end
else
%{
time_ago: gettext("Unknown"),
formatted: ""
}
end
end
defp get_received_at(packet) do
cond do
Map.has_key?(packet, :received_at) -> packet.received_at
Map.has_key?(packet, "received_at") -> packet["received_at"]
true -> nil
end
end
defp format_distance(km) when km < 1.0 do
"#{Float.round(km * 1000, 0)} m"
end
@ -237,7 +270,7 @@ defmodule AprsmeWeb.InfoLive.Show do
%{
callsign: p.sender,
ssid: p.ssid,
last_heard: PacketUtils.get_timestamp(p),
last_heard: format_timestamp_for_display(p),
packet: p
}
end)

View file

@ -346,7 +346,16 @@
<% end %>
</td>
<td class="opacity-70">
{ssid_info.last_heard || ""}
<%= if ssid_info.last_heard do %>
<div class="font-semibold">
{ssid_info.last_heard.time_ago}
</div>
<div class="text-xs opacity-70 font-mono">
{ssid_info.last_heard.formatted}
</div>
<% else %>
<span class="opacity-70">{gettext("Unknown")}</span>
<% end %>
</td>
</tr>
<% end %>
@ -441,7 +450,16 @@
<% end %>
</td>
<td class="opacity-70">
{neighbor.last_heard || ""}
<%= if neighbor.last_heard do %>
<div class="font-semibold">
{neighbor.last_heard.time_ago}
</div>
<div class="text-xs opacity-70 font-mono">
{neighbor.last_heard.formatted}
</div>
<% else %>
<span class="opacity-70">{gettext("Unknown")}</span>
<% end %>
</td>
</tr>
<% end %>