Show 'Latest data: date time (Xm ago)' in map badge

This commit is contained in:
Graham McIntire 2026-03-31 09:12:32 -05:00
parent e0d9900608
commit 24840c48d4
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -66,6 +66,17 @@ defmodule MicrowavepropWeb.MapLive do
{:noreply, socket}
end
defp time_ago(dt) do
seconds = DateTime.diff(DateTime.utc_now(), dt)
cond do
seconds < 60 -> "just now"
seconds < 3600 -> "#{div(seconds, 60)}m ago"
seconds < 86_400 -> "#{div(seconds, 3600)}h ago"
true -> "#{div(seconds, 86_400)}d ago"
end
end
defp selected_label(bands, selected_band) do
case Enum.find(bands, &(&1.freq_mhz == selected_band)) do
nil -> "Select Band"
@ -118,7 +129,7 @@ defmodule MicrowavepropWeb.MapLive do
</div>
<div :if={@valid_time} class="badge badge-ghost bg-base-100/90 shadow text-xs">
{Calendar.strftime(@valid_time, "%H:%M UTC")}
Latest data: {Calendar.strftime(@valid_time, "%b %d, %H:%M UTC")} ({time_ago(@valid_time)})
</div>
</div>
</div>