From 43ac5b57cfe56e3c89499fa0c1a038280ec95858 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 6 Feb 2026 19:42:06 +0000 Subject: [PATCH] time formatting --- .../Components/v2/monitors/MonitorStatBoxes.tsx | 15 ++++++++++----- client/src/Pages/Incidents/utils.ts | 7 +++++-- .../Pages/Maintenance/MaintenanceWindowTable.tsx | 7 ++++--- client/src/Pages/Uptime/Details/index.tsx | 2 +- server/src/service/business/diagnosticService.ts | 13 +++++++++---- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/client/src/Components/v2/monitors/MonitorStatBoxes.tsx b/client/src/Components/v2/monitors/MonitorStatBoxes.tsx index 65be06f3b..867f85516 100644 --- a/client/src/Components/v2/monitors/MonitorStatBoxes.tsx +++ b/client/src/Components/v2/monitors/MonitorStatBoxes.tsx @@ -1,9 +1,9 @@ import Stack from "@mui/material/Stack"; import { StatBox } from "@/Components/v2/design-elements"; +import prettyMilliseconds from "pretty-ms"; import { useTheme } from "@mui/material/styles"; import type { MonitorStats, Monitor } from "@/Types/Monitor"; -import { getHumanReadableDuration } from "@/Utils/timeUtilsLegacy.js"; import { getStatusPalette } from "@/Utils/MonitorUtils"; import { useTranslation } from "react-i18next"; @@ -32,11 +32,16 @@ export const MonitorStatBoxes = ({ // Determine time since last check const timeOfLastCheck = monitorStats?.lastCheckTimestamp || 0; - const timeSinceLastCheck = Date.now() - timeOfLastCheck; + const timeSinceLastCheck = Date.now() - timeOfLastCheck || 0; - const streakTime = getHumanReadableDuration(timeSinceLastFailure); + const options = { + secondsDecimalDigits: 0, + millisecondsDecimalDigits: 0, + }; - const lastCheckTime = getHumanReadableDuration(timeSinceLastCheck); + const streakTime = prettyMilliseconds(timeSinceLastFailure, options); + + const lastCheckTime = prettyMilliseconds(timeSinceLastCheck, options); const palette = getStatusPalette(monitor?.status); return ( @@ -55,7 +60,7 @@ export const MonitorStatBoxes = ({ /> {monitor?.type === "http" && ( diff --git a/client/src/Pages/Incidents/utils.ts b/client/src/Pages/Incidents/utils.ts index cba5744a4..6ff518a18 100644 --- a/client/src/Pages/Incidents/utils.ts +++ b/client/src/Pages/Incidents/utils.ts @@ -1,5 +1,5 @@ import type { Incident, IncidentSummaryItem } from "@/Types/Incident"; -import { getHumanReadableDuration } from "@/Utils/timeUtilsLegacy.js"; +import prettyMilliseconds from "pretty-ms"; type IncidentLike = Pick; @@ -24,5 +24,8 @@ export const getIncidentsDuration = (incident: IncidentLike | IncidentSummaryIte return "-"; } - return getHumanReadableDuration(durationMs); + return prettyMilliseconds(durationMs, { + secondsDecimalDigits: 0, + millisecondsDecimalDigits: 0, + }); }; diff --git a/client/src/Pages/Maintenance/MaintenanceWindowTable.tsx b/client/src/Pages/Maintenance/MaintenanceWindowTable.tsx index 53fe6bbee..42378bb67 100644 --- a/client/src/Pages/Maintenance/MaintenanceWindowTable.tsx +++ b/client/src/Pages/Maintenance/MaintenanceWindowTable.tsx @@ -1,10 +1,10 @@ import Typography from "@mui/material/Typography"; -import prettyMilliseconds from "pretty-ms"; import { Table, ValueLabel } from "@/Components/v2/design-elements"; import { Pagination } from "@/Components/v2/design-elements/Table"; import { ActionsMenu } from "@/Components/v2/actions-menu"; import { DialogInput } from "@/Components/v2/inputs/Dialog"; +import prettyMilliseconds from "pretty-ms"; import { useTheme } from "@mui/material"; import type { Header } from "@/Components/v2/design-elements/Table"; import type { ActionMenuItem } from "@/Components/v2/actions-menu"; @@ -15,7 +15,6 @@ import { useSelector, useDispatch } from "react-redux"; import type { RootState } from "@/Types/state"; import Box from "@mui/material/Box"; import { setRowsPerPage } from "@/Features/UI/uiSlice"; -import { formatDurationRounded } from "@/Utils/timeUtilsLegacy"; import dayjs from "dayjs"; import { useState } from "react"; import { useDelete, usePatch } from "@/Hooks/UseApi"; @@ -153,7 +152,9 @@ export const MaintenanceWindowTable = ({ id: "repeat", content: t("pages.maintenanceWindow.table.headers.repeat"), render: (row) => - row.repeat === 0 ? t("common.labels.na") : formatDurationRounded(row.repeat), + row.repeat === 0 + ? t("common.labels.na") + : prettyMilliseconds(row.repeat, { verbose: true }), }, { id: "actions", diff --git a/client/src/Pages/Uptime/Details/index.tsx b/client/src/Pages/Uptime/Details/index.tsx index 29c9f74db..b7910a17c 100644 --- a/client/src/Pages/Uptime/Details/index.tsx +++ b/client/src/Pages/Uptime/Details/index.tsx @@ -20,7 +20,7 @@ import { useGet } from "@/Hooks/UseApi"; import type { MonitorDetailsResponse } from "@/Types/Monitor"; import type { ChecksResponse } from "@/Types/Check"; import type { RootState } from "@/Types/state"; -import { formatDateWithTz } from "@/Utils/timeUtilsLegacy"; +import { formatDateWithTz } from "@/Utils/TimeUtils"; import { t } from "i18next"; const certificateDateFormat = "MMM D, YYYY h A"; diff --git a/server/src/service/business/diagnosticService.ts b/server/src/service/business/diagnosticService.ts index 6c49933a4..67729ce98 100644 --- a/server/src/service/business/diagnosticService.ts +++ b/server/src/service/business/diagnosticService.ts @@ -55,10 +55,15 @@ class DiagnosticService { }; const used = process.memoryUsage(); - const memoryUsage: Record = {}; - for (const key of Object.keys(used) as Array) { - memoryUsage[`${key}Mb`] = Math.round((used[key] / 1024 / 1024) * 100) / 100; // MB - } + + // In MB + const memoryUsage: Record = { + rss: Math.round((used.rss / 1024 / 1024) * 100) / 100, + heapTotal: Math.round((used.heapTotal / 1024 / 1024) * 100) / 100, + heapUsed: Math.round((used.heapUsed / 1024 / 1024) * 100) / 100, + external: Math.round((used.external / 1024 / 1024) * 100) / 100, + arrayBuffers: Math.round((used.arrayBuffers / 1024 / 1024) * 100) / 100, + }; // CPU Usage const cpuMetrics = await this.getCPUUsage();