track-duration
Version:
Converts milliseconds to a format like Spotify's track durations
37 lines (30 loc) • 845 B
JavaScript
;Object.defineProperty(exports,'__esModule',{value:true});// Generated by ReScript, PLEASE EDIT WITH CARE
function parseMinutes(s, h) {
return Math.floor(s / 60 - 60 * h);
}
function parseOutputSeconds(s) {
return Math.floor(s / 60 % 1 * 60);
}
function addLeadingZero(x) {
if (x < 10) {
return "0" + x.toString();
} else {
return x.toString();
}
}
function parse(ms) {
var s = ms / 1000;
var h = Math.floor(s / 3600);
var m = parseMinutes(s, h);
var outputSeconds = addLeadingZero(parseOutputSeconds(s));
if (h !== 0) {
return h.toString() + ":" + addLeadingZero(m) + ":" + outputSeconds;
} else {
return m.toString() + ":" + outputSeconds;
}
}
var parse_1 = parse;
/* No side effect */
var TrackDuration_bs = {
parse: parse_1
};exports.default=TrackDuration_bs;exports.parse=parse_1;