Skip to content

Commit

Permalink
[dashboard] Format Prebuild duration nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
jankeromnes authored and roboquat committed Dec 14, 2021
1 parent d4b15bf commit 3873545
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion components/dashboard/src/projects/Prebuilds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ export function prebuildStatusIcon(prebuild?: PrebuildWithStatus) {
}
}

function formatDuration(milliseconds: number) {
const hours = Math.floor(milliseconds / (1000 * 60 * 60));
return (hours > 0 ? `${hours}:` : '') + moment(milliseconds).format('mm:ss');
}

export function PrebuildInstanceStatus(props: { prebuildInstance?: WorkspaceInstance }) {
let status = <></>;
let details = <></>;
Expand Down Expand Up @@ -296,7 +301,7 @@ export function PrebuildInstanceStatus(props: { prebuildInstance?: WorkspaceInst
details = <div className="flex space-x-1 items-center text-gray-400">
<img className="h-4 w-4 filter-grayscale" src={StatusRunning} />
<span>{!!props.prebuildInstance?.stoppedTime
? `${Math.round(((new Date(props.prebuildInstance.stoppedTime).getTime()) - (new Date(props.prebuildInstance.creationTime).getTime())) / 1000)}s`
? formatDuration((new Date(props.prebuildInstance.stoppedTime).getTime()) - (new Date(props.prebuildInstance.creationTime).getTime()))
: '...'}</span>
</div>;
break;
Expand Down

0 comments on commit 3873545

Please sign in to comment.