From 894ea12144ae7ee9c63f54502d1ce26ac1345c99 Mon Sep 17 00:00:00 2001 From: Neil Hanlon Date: Wed, 21 Feb 2024 19:05:49 -0100 Subject: [PATCH] fix: display build subtask timing properly regardless of location --- peridot/ui/src/components/ProjectTasksSubtasks.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/peridot/ui/src/components/ProjectTasksSubtasks.tsx b/peridot/ui/src/components/ProjectTasksSubtasks.tsx index 1cdbd61d..06f2e4d1 100644 --- a/peridot/ui/src/components/ProjectTasksSubtasks.tsx +++ b/peridot/ui/src/components/ProjectTasksSubtasks.tsx @@ -48,6 +48,17 @@ import { translateTaskTypeToText, } from './ProjectTasks'; + +function formatDuration(ms) { + const seconds = Math.floor((ms / 1000) % 60); + const minutes = Math.floor((ms / (1000 * 60)) % 60); + const hours = Math.floor((ms / (1000 * 60 * 60)) % 24); + + return [hours, minutes, seconds] + .map(val => (val < 10 ? `0${val}` : val)) // Adding leading zeros if necessary + .join(':'); +} + export interface ProjectTasksSubtasksProps { subtasks: V1Subtask[]; } @@ -79,7 +90,7 @@ export const ProjectTasksSubtasks = (props: ProjectTasksSubtasksProps) => { (new Date(subtask.finishedAt) as any) - (new Date(subtask.createdAt) as any); subtaskDuration = ( - <>{new Date(difference - 3600000).toLocaleTimeString()} + <>{formatDuration(difference)} ); }