Skip to content

Commit 6ed6603

Browse files
authored
fix: improve formatting of minutes in build time (#5555)
1 parent 09ac309 commit 6ed6603

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

packages/core/src/helpers/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,19 @@ export const prettyTime = (seconds: number): string => {
342342
return `${format(seconds.toFixed(1))} s`;
343343
}
344344

345-
const minutes = seconds / 60;
346-
return `${format(minutes.toFixed(2))} m`;
345+
const minutes = Math.floor(seconds / 60);
346+
const minutesLabel = `${format(minutes.toFixed(0))} m`;
347+
const remainingSeconds = seconds % 60;
348+
349+
if (remainingSeconds === 0) {
350+
return minutesLabel;
351+
}
352+
353+
const secondsLabel = `${format(
354+
remainingSeconds.toFixed(remainingSeconds % 1 === 0 ? 0 : 1),
355+
)} s`;
356+
357+
return `${minutesLabel} ${secondsLabel}`;
347358
};
348359

349360
/**

packages/core/tests/helpers.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ test('should pretty time correctly', () => {
9191
expect(prettyTime(0.1234)).toEqual('0.12 s');
9292
expect(prettyTime(1.234)).toEqual('1.23 s');
9393
expect(prettyTime(12.34)).toEqual('12.3 s');
94-
expect(prettyTime(123.4)).toEqual('2.06 m');
95-
expect(prettyTime(1234)).toEqual('20.57 m');
94+
expect(prettyTime(120)).toEqual('2 m');
95+
expect(prettyTime(123.4)).toEqual('2 m 3.4 s');
96+
expect(prettyTime(1234)).toEqual('20 m 34 s');
97+
expect(prettyTime(1234.5)).toEqual('20 m 34.5 s');
9698
});
9799

98100
describe('pick', () => {

0 commit comments

Comments
 (0)