(timeInMs: number)
| 22 | * "10h 33m 17s" |
| 23 | */ |
| 24 | export function formatRelativeTimeInMs(timeInMs: number): string { |
| 25 | // We will always show 2 units of precision, e.g days and hours, or |
| 26 | // minutes and seconds, but not hours and minutes and seconds. |
| 27 | const result: string[] = []; |
| 28 | const timeInHours = timeInMs / (1000 * 60 * 60); |
| 29 | const days = Math.floor(timeInHours / 24); |
| 30 | if (days) { |
| 31 | result.push(days.toString() + 'd'); |
| 32 | } |
| 33 | |
| 34 | const remainingHours = timeInHours - days * 24; |
| 35 | const hours = Math.floor(remainingHours); |
| 36 | if (hours || days) { |
| 37 | result.push(hours.toString() + 'h'); |
| 38 | } |
| 39 | |
| 40 | const remainingMinutes = (remainingHours - hours) * 60; |
| 41 | const minutes = Math.floor(remainingMinutes); |
| 42 | if (minutes || hours || days) { |
| 43 | result.push(minutes.toString() + 'm'); |
| 44 | } |
| 45 | |
| 46 | const remainingSeconds = (remainingMinutes - minutes) * 60; |
| 47 | const seconds = Math.floor(remainingSeconds); |
| 48 | result.push(seconds.toString() + 's'); |
| 49 | |
| 50 | return result.join(' '); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Integers less than this number can be safely formatted as-is. |
no test coverage detected
searching dependent graphs…