aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2018-01-22 23:15:10 +1100
committerSam Potts <sam@potts.es>2018-01-22 23:15:10 +1100
commit5671235fd93eac4554d2c522461df813b589a7f4 (patch)
tree4278b90afa91cb8237b9faa5e50909c4ea832fc6 /src/js/utils.js
parent1dd5c9efd92bddff8b3ecb04ef53775c3c9b5b04 (diff)
downloadplyr-5671235fd93eac4554d2c522461df813b589a7f4.tar.lz
plyr-5671235fd93eac4554d2c522461df813b589a7f4.tar.xz
plyr-5671235fd93eac4554d2c522461df813b589a7f4.zip
Formatting, events and ad countdown added
Diffstat (limited to 'src/js/utils.js')
-rw-r--r--src/js/utils.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/js/utils.js b/src/js/utils.js
index 62ad8f9d..f82df2a4 100644
--- a/src/js/utils.js
+++ b/src/js/utils.js
@@ -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) {