2020-02-10 19:04:42 +00:00
|
|
|
module.exports = function msToTime(duration, format) {
|
2020-02-10 19:36:12 +00:00
|
|
|
var seconds = Math.floor((duration / 1000) % 60),
|
|
|
|
minutes = Math.floor((duration / (1000 * 60)) % 60),
|
2020-03-24 10:02:07 +00:00
|
|
|
hours = Math.floor((duration / (1000 * 60 * 60)) % 24),
|
|
|
|
days = Math.floor((duration / (1000 * 60 * 60 * 24)) % 24);
|
2020-02-05 20:02:53 +00:00
|
|
|
|
2020-02-10 19:36:12 +00:00
|
|
|
days = (days < 10) ? "0" + days : days;
|
|
|
|
hours = (hours < 10) ? "0" + hours : hours;
|
|
|
|
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
|
|
|
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
2020-02-05 20:02:53 +00:00
|
|
|
|
2020-02-10 19:36:12 +00:00
|
|
|
if (format === "hh:mm:ss") {
|
2020-02-10 19:04:42 +00:00
|
|
|
return `${hours}:${minutes}:${seconds}`;
|
2020-02-10 19:36:12 +00:00
|
|
|
} else if (format === "dd:hh:mm:ss") {
|
2020-02-10 19:24:09 +00:00
|
|
|
return `${days}:${hours}:${minutes}:${seconds}`;
|
2020-02-10 19:04:42 +00:00
|
|
|
}
|
2020-02-10 19:24:09 +00:00
|
|
|
}
|