Files
Checkmate/client/src/Pages/Incidents/utils.ts
T

29 lines
672 B
TypeScript

import type { Incident, IncidentSummaryItem } from "@/Types/Incident";
import { formatDuration } from "@/Utils/TimeUtils";
type IncidentLike = Pick<Incident, "startTime" | "endTime" | "status">;
export const getIncidentsDuration = (incident: IncidentLike | IncidentSummaryItem) => {
if (!incident?.startTime) {
return "-";
}
const startTime = new Date(incident?.startTime);
const endTime = incident.status
? new Date()
: incident?.endTime
? new Date(incident.endTime)
: null;
if (!endTime) {
return "-";
}
const durationMs = endTime.getTime() - startTime.getTime();
if (durationMs < 0) {
return "-";
}
return formatDuration(durationMs);
};