Skip to content

Commit ab433e5

Browse files
committed
feat(lib): add point two format duration
1 parent 8984685 commit ab433e5

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/libs/format-duration.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
function formatDuration(ms: number) {
22
const totalSeconds = Math.floor(ms / 1000);
3+
34
const h = Math.floor(totalSeconds / 3600);
45
const m = Math.floor((totalSeconds % 3600) / 60);
56
const s = totalSeconds % 60;
67

7-
return `${h}j ${m}m ${s}d`;
8+
const hh = String(h).padStart(2, '0');
9+
const mm = String(m).padStart(2, '0');
10+
const ss = String(s).padStart(2, '0');
11+
12+
return `${hh}j ${mm}m ${ss}d`;
813
}
914

1015
export { formatDuration };

0 commit comments

Comments
 (0)