From cf0d2c8e232a1af716c71cdd2218d180f7ecc02b Mon Sep 17 00:00:00 2001 From: yingjiechen <53926916+jj19100@users.noreply.github.com> Date: Tue, 7 Jan 2025 13:34:34 +0800 Subject: [PATCH] fix: build time display 7m 60s (#19108) Co-authored-by: chenyingjie --- packages/vite/src/node/utils.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 233f96810da833..65316c1f6fa8de 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -1501,11 +1501,17 @@ export function displayTime(time: number): string { return `${time.toFixed(2)}s` } - const mins = parseInt((time / 60).toString()) - const seconds = time % 60 + // Calculate total minutes and remaining seconds + const mins = Math.floor(time / 60) + const seconds = Math.round(time % 60) + + // Handle case where seconds rounds to 60 + if (seconds === 60) { + return `${mins + 1}m` + } // display: {X}m {Y}s - return `${mins}m${seconds < 1 ? '' : ` ${seconds.toFixed(0)}s`}` + return `${mins}m${seconds < 1 ? '' : ` ${seconds}s`}` } /**