Add startedAtMs to all processes

This commit is contained in:
Cooldude2606 committed 2026-02-01 21:30:00 +00:00
1 parent a4e4621eaa
commit 9729743a29
12 files changed
+118 -9

No files matched your search

@@ -63,3 +63,52 @@ export function RestartRequired(props: { system?: lib.SystemInfo }) {
<ReloadOutlined style={{ color: "yellow" }}/>
</Tooltip>;
}
/**
* Returns a human-readable duration between two dates.
*
* The output includes up to two most significant time units and omits
* leading zero units. Supported units are weeks, days, hours, minutes,
* and seconds.
*
* Examples: "1w 2d", "2d 3h", "1h 2m", "45s"
*
* @param date1 - The starting date.
* @param date2 - The ending date.
* @returns A duration string (e.g. "2d 3h").
*/
function humanAbsTimeDiff(date1: number, date2 = 0) {
let diffMs = Math.abs(date2 - date1);
const totalSeconds = Math.floor(diffMs / 1000);
const weeks = Math.floor(totalSeconds / 604800); // 7 * 24 * 60 * 60
const days = Math.floor((totalSeconds % 604800) / 86400);
const hours = Math.floor((totalSeconds % 86400) / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
if (weeks > 0) {
return days > 0 ? `${weeks}w ${days}d` : `${weeks}w`;
}
if (days > 0) {
return hours > 0 ? `${days}d ${hours}h` : `${days}d`;
}
if (hours > 0) {
return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
}
if (minutes > 0) {
return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
}
return `${seconds}s`;
}
export function MetricRelativeDate(props: { timeMs?: number }) {
if (!props.timeMs || props.timeMs === 0) {
return "N/A";
}
return `${new Date(props.timeMs).toLocaleString()} (${humanAbsTimeDiff(props.timeMs, Date.now())})`;
}