(totalSeconds: number)
| 158 | } |
| 159 | |
| 160 | export function formatDuration(totalSeconds: number): string { |
| 161 | if (!Number.isFinite(totalSeconds) || totalSeconds <= 0) return '0s'; |
| 162 | const seconds = Math.floor(totalSeconds); |
| 163 | const days = Math.floor(seconds / 86_400); |
| 164 | const hours = Math.floor((seconds % 86_400) / 3600); |
| 165 | const minutes = Math.floor((seconds % 3600) / 60); |
| 166 | const secs = seconds % 60; |
| 167 | const parts: string[] = []; |
| 168 | if (days) parts.push(`${String(days)}d`); |
| 169 | if (hours) parts.push(`${String(hours)}h`); |
| 170 | if (minutes) parts.push(`${String(minutes)}m`); |
| 171 | if (secs && parts.length === 0) parts.push(`${String(secs)}s`); |
| 172 | return parts.length > 0 ? parts.join(' ') : '0s'; |
| 173 | } |
| 174 | |
| 175 | function toInt(value: unknown): number | null { |
| 176 | if (typeof value === 'number') { |
no test coverage detected