This is an automated email from the ASF dual-hosted git repository. mintsweet pushed a commit to branch feat-pipeline-duration in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 44e8197a7434e12fb719e7130d403bbd5210185c Author: mintsweet <[email protected]> AuthorDate: Thu Sep 19 20:23:43 2024 +1200 feat: improve the pipeline duration display --- .../src/routes/pipeline/components/duration.tsx | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/config-ui/src/routes/pipeline/components/duration.tsx b/config-ui/src/routes/pipeline/components/duration.tsx index 7558f9fb3..67ea9e290 100644 --- a/config-ui/src/routes/pipeline/components/duration.tsx +++ b/config-ui/src/routes/pipeline/components/duration.tsx @@ -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; @@ -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>; };
