refactor: Improve calculation of incident duration in IncidentView component

This commit is contained in:
Simon Larsen 2024-05-08 11:10:20 +01:00
parent f35e50bab3
commit 8a4afe992c
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
2 changed files with 21 additions and 3 deletions

View File

@ -870,7 +870,7 @@ export default class OneUptimeDate {
formattedString += hours + ' hours';
}
if (mins > 0) {
if (mins >= 0) {
if (formattedString.length > 0) {
formattedString += ', ';
}

View File

@ -154,16 +154,34 @@ const IncidentView: FunctionComponent<PageComponentProps> = (
}
)?.startsAt;
if (!acknowledgeTime) {
const resolveTime: Date | undefined = incidentStateTimeline.find(
(timeline: IncidentStateTimeline) => {
return (
timeline.incidentStateId?.toString() ===
getResolvedState()?._id?.toString()
);
}
)?.startsAt;
if (!acknowledgeTime && !resolveTime) {
return (
'Not yet ' +
(getAcknowledgeState()?.name?.toLowerCase() || 'acknowledged')
);
}
if (!acknowledgeTime && resolveTime) {
return OneUptimeDate.convertMinutesToDaysHoursAndMinutes(
OneUptimeDate.getDifferenceInMinutes(
resolveTime,
incidentStartTime
)
);
}
return OneUptimeDate.convertMinutesToDaysHoursAndMinutes(
OneUptimeDate.getDifferenceInMinutes(
acknowledgeTime,
acknowledgeTime!,
incidentStartTime
)
);