Skip to content

Commit

Permalink
feat: improve the pipeline duration display (#8071)
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsweet authored Sep 19, 2024
1 parent ee21e3e commit 3ad9839
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions config-ui/src/routes/pipeline/components/duration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ import dayjs from 'dayjs';

import { IPipelineStatus } from '@/types';

const duration = (minute: number) => {
if (minute < 1) {
return '1m';
}

if (minute < 60) {
return `${Math.ceil(minute / 60)}m`;
}

if (minute < 60 * 24) {
const hours = Math.floor(minute / 60);
const minutes = minute - hours * 60;
return `${hours}h${minutes}m`;
}

const days = Math.floor(minute / (60 * 24));
const hours = Math.floor((minute - days * 60 * 24) / 60);
const minutes = minute - days * 60 * 24 - hours * 60;

return `${days}d${hours}h${minutes}m`;
};

interface Props {
status: IPipelineStatus;
beganAt: string | null;
Expand All @@ -36,12 +58,12 @@ export const PipelineDuration = ({ status, beganAt, finishedAt }: Props) => {
status,
)
) {
return <span>{dayjs(beganAt).toNow(true)}</span>;
return <span>{duration(dayjs(beganAt).diff(dayjs(), 'm'))}</span>;
}

if (!finishedAt) {
return <span>-</span>;
}

return <span>{dayjs(beganAt).from(finishedAt, true)}</span>;
return <span>{duration(dayjs(beganAt).diff(dayjs(finishedAt), 'm'))}</span>;
};

0 comments on commit 3ad9839

Please sign in to comment.