MCPcopy
hub / github.com/bbc/peaks.js / formatTime

Function formatTime

src/utils.js:21–46  ·  view source on GitHub ↗
(time, precision)

Source from the content-addressed store, hash-verified

19 */
20
21export 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.

Callers 3

utils-spec.jsFile · 0.90
WaveformViewFunction · 0.90
WaveformAxisFunction · 0.90

Calls 1

zeroPadFunction · 0.85

Tested by

no test coverage detected