MCPcopy Create free account
hub / github.com/anomalyco/opencode / formatDuration

Function formatDuration

packages/tui/src/util/format.ts:1–20  ·  view source on GitHub ↗
(secs: number)

Source from the content-addressed store, hash-verified

1export function formatDuration(secs: number) {
2 if (secs <= 0) return ""
3 if (secs < 60) return `${secs}s`
4 if (secs < 3600) {
5 const mins = Math.floor(secs / 60)
6 const remaining = secs % 60
7 return remaining > 0 ? `${mins}m ${remaining}s` : `${mins}m`
8 }
9 if (secs < 86400) {
10 const hours = Math.floor(secs / 3600)
11 const remaining = Math.floor((secs % 3600) / 60)
12 return remaining > 0 ? `${hours}h ${remaining}m` : `${hours}h`
13 }
14 if (secs < 604800) {
15 const days = Math.floor(secs / 86400)
16 return days === 1 ? "~1 day" : `~${days} days`
17 }
18 const weeks = Math.floor(secs / 604800)
19 return weeks === 1 ? "~1 week" : `~${weeks} weeks`
20}

Callers 2

format.test.tsFile · 0.90
retryTextFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected