Commit fe3ea9da authored by Richard Blechinger's avatar Richard Blechinger
Browse files

Fix issues with calculation of nanoseconds

parent 5ed0887b
...@@ -327,8 +327,8 @@ ...@@ -327,8 +327,8 @@
const totalDuration = this.playlistEditor.entries.reduce((acc, entry) => { const totalDuration = this.playlistEditor.entries.reduce((acc, entry) => {
const newDuration = entry.file const newDuration = entry.file
? acc + this.getFileById(entry.file.id).duration ? acc + this.durationInSeconds(this.getFileById(entry.file.id).duration)
: acc + entry.duration : acc + this.durationInSeconds(entry.duration)
if (Number.isNaN(newDuration)) { if (Number.isNaN(newDuration)) {
return acc return acc
...@@ -337,7 +337,8 @@ ...@@ -337,7 +337,8 @@
return newDuration return newDuration
}, 0) }, 0)
return this.prettyNanoseconds(totalDuration) const durationInNanoseconds = totalDuration * 1000 * 1000 * 1000;
return this.prettyNanoseconds(durationInNanoseconds)
}, },
...mapGetters({ ...mapGetters({
......
<template> <template>
<div> <div>
<edit-playlists-modal ref="editPlaylistsModal" />
<!-- Only display a spinner if the playlists are not loaded yet --> <!-- Only display a spinner if the playlists are not loaded yet -->
<div v-if="!loaded.playlists"> <div v-if="!loaded.playlists">
<b-row> <b-row>
...@@ -182,7 +180,7 @@ export default { ...@@ -182,7 +180,7 @@ export default {
} }
const totalDuration = item.entries.reduce((acc, entry) => { const totalDuration = item.entries.reduce((acc, entry) => {
const newDuration = acc + entry.duration; const newDuration = acc + this.durationInSeconds(entry.duration);
if (Number.isNaN(newDuration)) { if (Number.isNaN(newDuration)) {
return acc; return acc;
...@@ -191,7 +189,8 @@ export default { ...@@ -191,7 +189,8 @@ export default {
return newDuration return newDuration
}, 0) }, 0)
return this.prettyNanoseconds(totalDuration) const totalDurationInNanoseconds = totalDuration * 1000 * 1000 * 1000;
return this.prettyNanoseconds(totalDurationInNanoseconds)
}, },
}, },
} }
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
<span <span
:class="{'is-mismatched': isMismatchedLength(data) }" :class="{'is-mismatched': isMismatchedLength(data) }"
> >
{{ prettyNanoseconds(playlistDuration(data)) }} {{ playlistDuration(data) }}
<abbr <abbr
v-if="isMismatchedLength(data)" v-if="isMismatchedLength(data)"
...@@ -212,21 +212,22 @@ export default { ...@@ -212,21 +212,22 @@ export default {
let delta = 0; let delta = 0;
const totalDuration = item.entries.reduce((acc, entry) => { const totalDuration = item.entries.reduce((acc, entry) => {
const newDuration = acc + entry.duration; const newDuration = acc + this.durationInSeconds(entry.duration);
if (Number.isNaN(newDuration)) { if (Number.isNaN(newDuration)) {
return acc; return acc;
} }
return newDuration return newDuration
}, 0); }, 0)
const unknowns = item.entries.filter(entry => !entry.duration); const unknowns = item.entries.filter(entry => !entry.duration);
if (unknowns.length === 1) { if (unknowns.length === 1) {
delta = this.timeslotDurationInNs - totalDuration; delta = this.durationInSeconds(this.timeslotDurationInNs) - totalDuration;
} }
return totalDuration + delta const totalDurationInNanoseconds = (totalDuration + delta) * 1000 * 1000 * 1000
return this.prettyNanoseconds(totalDurationInNanoseconds)
}, },
isMismatchedLength(playlist) { isMismatchedLength(playlist) {
......
...@@ -79,12 +79,20 @@ export default { ...@@ -79,12 +79,20 @@ export default {
} }
return duration return duration
}, },
durationInSeconds: function(ns) {
const durationInMilliseconds = Math.floor(ns / 1000 / 1000);
return Math.floor(durationInMilliseconds / 1000);
},
prettyNanoseconds: function(ns) { prettyNanoseconds: function(ns) {
var sec_total = ns / 1000 / 1000 / 1000 const durationInMilliseconds = Math.floor(ns / 1000 / 1000);
var hours = Math.floor(sec_total / 3600)
var minutes = Math.floor((sec_total - (hours * 3600)) / 60) const seconds = parseInt((durationInMilliseconds / 1000) % 60),
var seconds = Math.floor((sec_total - (hours * 3600) - (minutes * 60)) * 10) / 10 minutes = parseInt((durationInMilliseconds / (1000 * 60)) % 60),
return this.leadingZero(hours) + ':' + this.leadingZero(minutes) + ':' + this.leadingZero(seconds.toFixed(0)) hours = parseInt((durationInMilliseconds / (1000 * 60 * 60)) % 24);
return this.leadingZero(hours) + ':' + this.leadingZero(minutes) + ':' + this.leadingZero(seconds)
}, },
nanosecondsToMinutes: function(ns) { nanosecondsToMinutes: function(ns) {
return ns / 1000 / 1000 / 1000 / 60; return ns / 1000 / 1000 / 1000 / 60;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment