( totalSeconds: number, )
| 236 | /** Decompose a seconds value into the largest unit that divides it evenly, |
| 237 | * so 300 → 5 minutes, 3600 → 1 hour, 23 → 23 seconds. */ |
| 238 | export const fromSeconds = ( |
| 239 | totalSeconds: number, |
| 240 | ): { amount: number; unit: DurationUnit } => { |
| 241 | for (const unit of Object.keys(SECONDS_PER_UNIT) as DurationUnit[]) { |
| 242 | const perUnit = SECONDS_PER_UNIT[unit]; |
| 243 | if (totalSeconds % perUnit === 0) { |
| 244 | return { amount: totalSeconds / perUnit, unit }; |
| 245 | } |
| 246 | } |
| 247 | return { amount: totalSeconds, unit: "seconds" }; |
| 248 | }; |
no test coverage detected