Formatting, events and ad countdown added

This commit is contained in:
Sam Potts
2018-01-22 23:15:10 +11:00
parent 1dd5c9efd9
commit 5671235fd9
11 changed files with 199 additions and 113 deletions
+26
View File
@@ -605,6 +605,32 @@ const utils = {
return (current / max * 100).toFixed(2);
},
// Time helpers
getHours(value) { return parseInt((value / 60 / 60) % 60, 10); },
getMinutes(value) { return parseInt((value / 60) % 60, 10); },
getSeconds(value) { return parseInt(value % 60, 10); },
// Format time to UI friendly string
formatTime(time = 0, displayHours = false, inverted = false) {
// Format time component to add leading zero
const format = value => `0${value}`.slice(-2);
// Breakdown to hours, mins, secs
let hours = this.getHours(time);
const mins = this.getMinutes(time);
const secs = this.getSeconds(time);
// Do we need to display hours?
if (displayHours || hours > 0) {
hours = `${hours}:`;
} else {
hours = '';
}
// Render
return `${inverted ? '-' : ''}${hours}${format(mins)}:${format(secs)}`;
},
// Deep extend destination object with N more objects
extend(target = {}, ...sources) {
if (!sources.length) {