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

Fix issues with calculation of nanoseconds

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