Show 'Latest data: date time (Xm ago)' in map badge
This commit is contained in:
parent
e0d9900608
commit
24840c48d4
1 changed files with 12 additions and 1 deletions
|
|
@ -66,6 +66,17 @@ defmodule MicrowavepropWeb.MapLive do
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
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
|
defp selected_label(bands, selected_band) do
|
||||||
case Enum.find(bands, &(&1.freq_mhz == selected_band)) do
|
case Enum.find(bands, &(&1.freq_mhz == selected_band)) do
|
||||||
nil -> "Select Band"
|
nil -> "Select Band"
|
||||||
|
|
@ -118,7 +129,7 @@ defmodule MicrowavepropWeb.MapLive do
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div :if={@valid_time} class="badge badge-ghost bg-base-100/90 shadow text-xs">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue