From b40a029599f2ca217e8ad1497da2b7ee792e64a4 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Wed, 3 Apr 2024 14:46:55 +0200 Subject: [PATCH] More timestamp handling fixes/improvements Signed-off-by: Julius Volz --- web/ui/mantine-ui/src/pages/StatusPage.tsx | 3 ++- web/ui/mantine-ui/src/pages/TSDBStatusPage.tsx | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/web/ui/mantine-ui/src/pages/StatusPage.tsx b/web/ui/mantine-ui/src/pages/StatusPage.tsx index 5555e74ef..963813f9d 100644 --- a/web/ui/mantine-ui/src/pages/StatusPage.tsx +++ b/web/ui/mantine-ui/src/pages/StatusPage.tsx @@ -1,6 +1,7 @@ import { Card, Group, Stack, Table, Text } from "@mantine/core"; import { useSuspenseAPIQuery } from "../api/api"; import { IconRun, IconWall } from "@tabler/icons-react"; +import { formatTimestamp } from "../lib/formatTime"; const statusConfig: Record< string, @@ -11,7 +12,7 @@ const statusConfig: Record< > = { startTime: { title: "Start time", - formatValue: (v: string) => new Date(v).toUTCString(), + formatValue: (v: string) => formatTimestamp(new Date(v).valueOf() / 1000), }, CWD: { title: "Working directory" }, reloadConfigSuccess: { diff --git a/web/ui/mantine-ui/src/pages/TSDBStatusPage.tsx b/web/ui/mantine-ui/src/pages/TSDBStatusPage.tsx index 5da498e0d..5948e2721 100644 --- a/web/ui/mantine-ui/src/pages/TSDBStatusPage.tsx +++ b/web/ui/mantine-ui/src/pages/TSDBStatusPage.tsx @@ -1,6 +1,8 @@ import { Stack, Card, Group, Table, Text } from "@mantine/core"; import { useSuspenseAPIQuery } from "../api/api"; import { TSDBMap } from "../api/responseTypes/tsdbStatus"; +import { useAppSelector } from "../state/hooks"; +import { formatTimestamp } from "../lib/formatTime"; export default function TSDBStatusPage() { const { @@ -15,23 +17,27 @@ export default function TSDBStatusPage() { }, } = useSuspenseAPIQuery({ path: `/status/tsdb` }); + const useLocalTime = useAppSelector((state) => state.settings.useLocalTime); + const unixToTime = (unix: number): string => { - try { - return `${new Date(unix).toISOString()} (${unix})`; - } catch { + const formatted = formatTimestamp(unix, useLocalTime); + if (formatted === "Invalid Date") { if (numSeries === 0) { return "No datapoints yet"; } return `Error parsing time (${unix})`; } + + return formatted; }; + const { chunkCount, numSeries, numLabelPairs, minTime, maxTime } = headStats; const stats = [ { name: "Number of Series", value: numSeries }, { name: "Number of Chunks", value: chunkCount }, { name: "Number of Label Pairs", value: numLabelPairs }, - { name: "Current Min Time", value: `${unixToTime(minTime)}` }, - { name: "Current Max Time", value: `${unixToTime(maxTime)}` }, + { name: "Current Min Time", value: `${unixToTime(minTime / 1000)}` }, + { name: "Current Max Time", value: `${unixToTime(maxTime / 1000)}` }, ]; return (