From cf9f46ba35ad25b9a0b0a20ae611d72a57b2b14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Tue, 11 Jun 2019 17:01:17 +0200 Subject: [PATCH] Use template literals for 'formatTime' --- resources/media-controls.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/resources/media-controls.js b/resources/media-controls.js index dc73d9ea6d3..2965b5d16b7 100644 --- a/resources/media-controls.js +++ b/resources/media-controls.js @@ -58,24 +58,18 @@ } function formatTime(time, showHours = false) { - // Format the duration as "h:mm:ss" or "m:ss" - time = Math.round(time / 1000); - let hours = Math.floor(time / 3600); - let mins = Math.floor((time % 3600) / 60); - let secs = Math.floor(time % 60); - let timeString; - if (secs < 10) { - secs = "0" + secs; - } - if (hours || showHours) { - if (mins < 10) { - mins = "0" + mins; - } - timeString = hours + ":" + mins + ":" + secs; - } else { - timeString = mins + ":" + secs; - } - return timeString; + // Format the duration as "h:mm:ss" or "m:ss" + time = Math.round(time / 1000); + + const hours = Math.floor(time / 3600); + const mins = Math.floor((time % 3600) / 60); + const secs = Math.floor(time % 60); + + const formattedHours = hours || showHours ? + `${hours.toString().padStart(2, "0")}:` : + ""; + + return `${formattedHours}${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`; } class MediaControls {