(time, precision)
| 19 | */ |
| 20 | |
| 21 | export function formatTime(time, precision) { |
| 22 | let result = []; |
| 23 | |
| 24 | const fractionSeconds = Math.floor((time % 1) * Math.pow(10, precision)); |
| 25 | const seconds = Math.floor(time); |
| 26 | const minutes = Math.floor(seconds / 60); |
| 27 | const hours = Math.floor(minutes / 60); |
| 28 | |
| 29 | if (hours > 0) { |
| 30 | result.push(hours); // Hours |
| 31 | } |
| 32 | result.push(minutes % 60); // Mins |
| 33 | result.push(seconds % 60); // Seconds |
| 34 | |
| 35 | for (let i = 0; i < result.length; i++) { |
| 36 | result[i] = zeroPad(result[i], 2); |
| 37 | } |
| 38 | |
| 39 | result = result.join(':'); |
| 40 | |
| 41 | if (precision > 0) { |
| 42 | result += '.' + zeroPad(fractionSeconds, precision); |
| 43 | } |
| 44 | |
| 45 | return result; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Rounds the given value up to the nearest given multiple. |
no test coverage detected