convert total time to hms

This commit is contained in:
vapormusic 2021-12-30 10:31:32 +07:00
parent 907ea987c0
commit 5d3db3360d
2 changed files with 18 additions and 4 deletions

View file

@ -1579,8 +1579,11 @@ const app = new Vue({
getTotalTime() {
try {
if (app.showingPlaylist.relationships.tracks.data.length > 0) {
time = Math.round([].concat(...app.showingPlaylist.relationships.tracks.data).reduce((a, { attributes: { durationInMillis } }) => a + durationInMillis, 0) / 60000);
return app.showingPlaylist.relationships.tracks.data.length + " tracks, " + time + " mins.";
let time = Math.round([].concat(...app.showingPlaylist.relationships.tracks.data).reduce((a, { attributes: { durationInMillis } }) => a + durationInMillis, 0) / 1000);
let hours = Math.floor(time / 3600)
let mins = Math.floor(time / 60) % 60
let secs = time % 60
return app.showingPlaylist.relationships.tracks.data.length + " tracks, " + ((hours > 0) ? (hours + (" hour" + ((hours > 1) ? "s, " : ", "))) : "" ) + ((mins > 0) ? (mins + (" minute" + ((mins > 1) ? "s, " : ", "))) : "" )+ secs + (" second" + ((secs > 1) ? "s." : "."));
} else return ""
} catch (err) {
return ""

View file

@ -84,13 +84,13 @@
</div>
<div class="playlist-time">
{{data.attributes.releaseDate}}
{{getFormattedDate(data.attributes.releaseDate)}}
</div>
<div class="playlist-time total">{{app.getTotalTime()}}</div>
<div class="playlist-time item-navigate" @click="app.searchAndNavigate(data,'recordLabel') "
style="width: 50%;">
{{data.attributes.copyright}}
</div>
<div class="playlist-time">{{app.getTotalTime()}}</div>
</div>
</template>
</div>
@ -225,6 +225,17 @@
kind = data.attributes.playParams.kind;
id = data.attributes.playParams.id;
return `${kind}:${id}`
},
getFormattedDate: function (date) {
if (date == null || date === "") return "";
try{
var releaseDate = new Date(date);
month = new Intl.DateTimeFormat('en-US', { month: 'long'}).format(releaseDate);
date = releaseDate.getDate();
year = releaseDate.getFullYear();
return date + " " + month + " " + year;
} catch (e){ return ""}
}
}
})