More timestamp handling fixes/improvements

Signed-off-by: Julius Volz <julius.volz@gmail.com>
pull/14448/head
Julius Volz 2024-04-03 14:46:55 +02:00
parent 3c44f43815
commit b40a029599
2 changed files with 13 additions and 6 deletions

View File

@ -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: {

View File

@ -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<TSDBMap>({ 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 (