return time string

This commit is contained in:
Alex Holliday committed 2025-06-17 13:41:25 +08:00
1 parent 1298b23844
commit 9c40021318
3 files changed
+8 -23

No files matched your search

@@ -5,13 +5,8 @@ import { getHumanReadableDuration } from "../../../../../Utils/timeUtils";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
const PageSpeedStatusBoxes = ({ shouldRender, monitor }) => { const PageSpeedStatusBoxes = ({ shouldRender, monitor }) => {
const { time: uptimeDuration, units: uptimeUnits } = getHumanReadableDuration( const uptimeDuration = getHumanReadableDuration(monitor?.uptimeDuration);
monitor?.uptimeDuration const time = getHumanReadableDuration(monitor?.lastChecked);
);
const { time: lastCheckTime, units: lastCheckUnits } = getHumanReadableDuration(
monitor?.lastChecked
);
const { t } = useTranslation(); const { t } = useTranslation();
@@ -22,7 +17,6 @@ const PageSpeedStatusBoxes = ({ shouldRender, monitor }) => {
subHeading={ subHeading={
<> <>
{uptimeDuration} {uptimeDuration}
<Typography component="span">{uptimeUnits}</Typography>
<Typography component="span">{t("ago")}</Typography> <Typography component="span">{t("ago")}</Typography>
</> </>
} }
@@ -31,8 +25,7 @@ const PageSpeedStatusBoxes = ({ shouldRender, monitor }) => {
heading="last check" heading="last check"
subHeading={ subHeading={
<> <>
{lastCheckTime} {time}
<Typography component="span">{lastCheckUnits}</Typography>
<Typography component="span">{t("ago")}</Typography> <Typography component="span">{t("ago")}</Typography>
</> </>
} }
@@ -24,30 +24,22 @@ const UptimeStatusBoxes = ({
const timeOfLastCheck = monitorStats?.lastCheckTimestamp; const timeOfLastCheck = monitorStats?.lastCheckTimestamp;
const timeSinceLastCheck = Date.now() - timeOfLastCheck; const timeSinceLastCheck = Date.now() - timeOfLastCheck;
const { time: streakTime, units: streakUnits } = const streakTime = getHumanReadableDuration(timeSinceLastFailure);
getHumanReadableDuration(timeSinceLastFailure);
const { time: lastCheckTime, units: lastCheckUnits } = const lastCheckTime = getHumanReadableDuration(timeSinceLastCheck);
getHumanReadableDuration(timeSinceLastCheck);
return ( return (
<StatusBoxes shouldRender={!isLoading}> <StatusBoxes shouldRender={!isLoading}>
<StatBox <StatBox
gradient={true} gradient={true}
status={determineState(monitor)} status={determineState(monitor)}
heading={"active for"} heading={"active for"}
subHeading={ subHeading={streakTime}
<>
{streakTime}
<Typography component="span">{streakUnits}</Typography>
</>
}
/> />
<StatBox <StatBox
heading="last check" heading="last check"
subHeading={ subHeading={
<> <>
{lastCheckTime} {lastCheckTime}
<Typography component="span">{lastCheckUnits}</Typography>
<Typography component="span">{"ago"}</Typography> <Typography component="span">{"ago"}</Typography>
</> </>
} }
+2 -2
View File
@@ -104,10 +104,10 @@ export const getHumanReadableDuration = (ms) => {
if (result.length === 0) { if (result.length === 0) {
// fallback for durations < 1s // fallback for durations < 1s
return { time: 0, units: "seconds" }; return "0s";
} }
return { time: result.join(" "), units: null }; return result.join(" ");
}; };
export const formatDate = (date, customOptions) => { export const formatDate = (date, customOptions) => {