MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / formatDuration

Function formatDuration

source code/utils/format.ts:36–97  ·  view source on GitHub ↗
(
  ms: number,
  options?: { hideTrailingZeros?: boolean; mostSignificantOnly?: boolean },
)

Source from the content-addressed store, hash-verified

34}
35
36export function formatDuration(
37 ms: number,
38 options?: { hideTrailingZeros?: boolean; mostSignificantOnly?: boolean },
39): string {
40 if (ms < 60000) {
41 // Special case for 0
42 if (ms === 0) {
43 return '0s'
44 }
45 // For durations < 1s, show 1 decimal place (e.g., 0.5s)
46 if (ms < 1) {
47 const s = (ms / 1000).toFixed(1)
48 return `${s}s`
49 }
50 const s = Math.floor(ms / 1000).toString()
51 return `${s}s`
52 }
53
54 let days = Math.floor(ms / 86400000)
55 let hours = Math.floor((ms % 86400000) / 3600000)
56 let minutes = Math.floor((ms % 3600000) / 60000)
57 let seconds = Math.round((ms % 60000) / 1000)
58
59 // Handle rounding carry-over (e.g., 59.5s rounds to 60s)
60 if (seconds === 60) {
61 seconds = 0
62 minutes++
63 }
64 if (minutes === 60) {
65 minutes = 0
66 hours++
67 }
68 if (hours === 24) {
69 hours = 0
70 days++
71 }
72
73 const hide = options?.hideTrailingZeros
74
75 if (options?.mostSignificantOnly) {
76 if (days > 0) return `${days}d`
77 if (hours > 0) return `${hours}h`
78 if (minutes > 0) return `${minutes}m`
79 return `${seconds}s`
80 }
81
82 if (days > 0) {
83 if (hide && hours === 0 && minutes === 0) return `${days}d`
84 if (hide && minutes === 0) return `${days}d ${hours}h`
85 return `${days}d ${hours}h ${minutes}m`
86 }
87 if (hours > 0) {
88 if (hide && minutes === 0 && seconds === 0) return `${hours}h`
89 if (hide && seconds === 0) return `${hours}h ${minutes}m`
90 return `${hours}h ${minutes}m ${seconds}s`
91 }
92 if (minutes > 0) {
93 if (hide && seconds === 0) return `${minutes}m`

Callers 15

#handleExitMethod · 0.70
formatTotalCostFunction · 0.50
renderToolResultMessageFunction · 0.50
AgentLineFunction · 0.50
OverviewTabFunction · 0.50
renderOverviewToAnsiFunction · 0.50
SpinnerWithVerbInnerFunction · 0.50
ShellTimeDisplayFunction · 0.50
TeammateSpinnerLineFunction · 0.50
SpinnerAnimationRowFunction · 0.50
TurnDurationMessageFunction · 0.50

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected