mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Use template literals for 'formatTime'
This commit is contained in:
parent
a8419c4a86
commit
cf9f46ba35
1 changed files with 12 additions and 18 deletions
|
@ -58,24 +58,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatTime(time, showHours = false) {
|
function formatTime(time, showHours = false) {
|
||||||
// Format the duration as "h:mm:ss" or "m:ss"
|
// Format the duration as "h:mm:ss" or "m:ss"
|
||||||
time = Math.round(time / 1000);
|
time = Math.round(time / 1000);
|
||||||
let hours = Math.floor(time / 3600);
|
|
||||||
let mins = Math.floor((time % 3600) / 60);
|
const hours = Math.floor(time / 3600);
|
||||||
let secs = Math.floor(time % 60);
|
const mins = Math.floor((time % 3600) / 60);
|
||||||
let timeString;
|
const secs = Math.floor(time % 60);
|
||||||
if (secs < 10) {
|
|
||||||
secs = "0" + secs;
|
const formattedHours = hours || showHours ?
|
||||||
}
|
`${hours.toString().padStart(2, "0")}:` :
|
||||||
if (hours || showHours) {
|
"";
|
||||||
if (mins < 10) {
|
|
||||||
mins = "0" + mins;
|
return `${formattedHours}${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
|
||||||
}
|
|
||||||
timeString = hours + ":" + mins + ":" + secs;
|
|
||||||
} else {
|
|
||||||
timeString = mins + ":" + secs;
|
|
||||||
}
|
|
||||||
return timeString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MediaControls {
|
class MediaControls {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue