diff --git a/lib/towerops_web/helpers/time_helpers.ex b/lib/towerops_web/helpers/time_helpers.ex index 0510c126..c45b2c8c 100644 --- a/lib/towerops_web/helpers/time_helpers.ex +++ b/lib/towerops_web/helpers/time_helpers.ex @@ -181,8 +181,21 @@ defmodule ToweropsWeb.TimeHelpers do end @doc """ - Formats a DateTime into a short date string in UTC. + Formats a DateTime into a short "Mon DD HH:MM" string in the given timezone. """ + @spec format_short_datetime(DateTime.t() | nil, String.t()) :: String.t() + def format_short_datetime(nil, _timezone), do: "—" + + def format_short_datetime(datetime, timezone) do + case to_user_timezone(datetime, timezone || "UTC") do + {:ok, shifted_dt, _tz_abbr} -> + Calendar.strftime(shifted_dt, "%b %d %H:%M") + + {:error, _} -> + Calendar.strftime(datetime, "%b %d %H:%M") + end + end + @spec format_date(DateTime.t() | nil) :: String.t() def format_date(datetime), do: format_date(datetime, "UTC") diff --git a/lib/towerops_web/live/dashboard_live.ex b/lib/towerops_web/live/dashboard_live.ex index 43149a1f..d88a811a 100644 --- a/lib/towerops_web/live/dashboard_live.ex +++ b/lib/towerops_web/live/dashboard_live.ex @@ -27,7 +27,9 @@ defmodule ToweropsWeb.DashboardLive do socket |> assign(:page_title, organization.name) |> assign(:device_count, device_count) - |> assign(:insight_source, nil)} + |> assign(:insight_source, nil) + |> assign(:timezone, socket.assigns.current_scope.timezone) + |> assign(:time_format, socket.assigns.current_scope.time_format)} end @impl true @@ -259,10 +261,6 @@ defmodule ToweropsWeb.DashboardLive do end end - defp site_health_border(:red), do: "border-red-300 bg-red-50/50 dark:border-red-800 dark:bg-red-950/20" - defp site_health_border(:yellow), do: "border-yellow-300 bg-yellow-50/50 dark:border-yellow-800 dark:bg-yellow-950/20" - defp site_health_border(_), do: "border-gray-200 bg-white dark:border-white/10 dark:bg-gray-800/50" - defp site_health_dot(:red), do: "bg-red-500" defp site_health_dot(:yellow), do: "bg-yellow-500" defp site_health_dot(_), do: "bg-green-500" @@ -287,4 +285,8 @@ defmodule ToweropsWeb.DashboardLive do defp format_qoe(nil), do: "—" defp format_qoe(score), do: :erlang.float_to_binary(score / 1, decimals: 1) + + defp format_short_datetime(datetime, timezone) do + ToweropsWeb.TimeHelpers.format_short_datetime(datetime, timezone) + end end diff --git a/lib/towerops_web/live/dashboard_live.html.heex b/lib/towerops_web/live/dashboard_live.html.heex index 134f9356..2764c1ec 100644 --- a/lib/towerops_web/live/dashboard_live.html.heex +++ b/lib/towerops_web/live/dashboard_live.html.heex @@ -14,7 +14,7 @@ <%= if assigns[:last_updated] do %>