From c6323f8ad9b1ff21e96cd79c496a38554ec937b2 Mon Sep 17 00:00:00 2001 From: advplyr Date: Wed, 11 May 2022 17:35:04 -0500 Subject: [PATCH] Fix:Local playback session store date/dayOfWeek string to be used in stats --- client/components/stats/Heatmap.vue | 2 +- client/plugins/init.client.js | 10 +++++----- server/managers/PlaybackSessionManager.js | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/client/components/stats/Heatmap.vue b/client/components/stats/Heatmap.vue index 8699d93c..b4e638e9 100644 --- a/client/components/stats/Heatmap.vue +++ b/client/components/stats/Heatmap.vue @@ -154,7 +154,7 @@ export default { this.showingTooltipIndex = index this.tooltipEl.style.display = 'block' - this.tooltipTextEl.innerHTML = block.value ? `${block.value} minutes listening on ${block.datePretty}` : `No listening sessions on ${block.datePretty}` + this.tooltipTextEl.innerHTML = block.value ? `${this.$elapsedPretty(block.value, true)} listening on ${block.datePretty}` : `No listening sessions on ${block.datePretty}` const calculateRect = this.tooltipEl.getBoundingClientRect() diff --git a/client/plugins/init.client.js b/client/plugins/init.client.js index e69f7f69..c9c867eb 100644 --- a/client/plugins/init.client.js +++ b/client/plugins/init.client.js @@ -40,20 +40,20 @@ Vue.prototype.$bytesPretty = (bytes, decimals = 2) => { return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i] } -Vue.prototype.$elapsedPretty = (seconds) => { +Vue.prototype.$elapsedPretty = (seconds, useFullNames = false) => { if (seconds < 60) { - return `${Math.floor(seconds)} sec` + return `${Math.floor(seconds)} sec${useFullNames ? 'onds' : ''}` } var minutes = Math.floor(seconds / 60) if (minutes < 70) { - return `${minutes} min` + return `${minutes} min${useFullNames ? `ute${minutes === 1 ? '' : 's'}` : ''}` } var hours = Math.floor(minutes / 60) minutes -= hours * 60 if (!minutes) { - return `${hours} hr` + return `${hours} ${useFullNames ? 'hours' : 'hr'}` } - return `${hours} hr ${minutes} min` + return `${hours} ${useFullNames ? `hour${hours === 1 ? '' : 's'}` : 'hr'} ${minutes} ${useFullNames ? `minute${minutes === 1 ? '' : 's'}` : 'min'}` } Vue.prototype.$secondsToTimestamp = (seconds) => { diff --git a/server/managers/PlaybackSessionManager.js b/server/managers/PlaybackSessionManager.js index 1c1086ff..50d1ecd0 100644 --- a/server/managers/PlaybackSessionManager.js +++ b/server/managers/PlaybackSessionManager.js @@ -1,4 +1,5 @@ const Path = require('path') +const date = require('date-and-time') const { PlayMethod } = require('../utils/constants') const PlaybackSession = require('../objects/PlaybackSession') const Stream = require('../objects/Stream') @@ -53,6 +54,8 @@ class PlaybackSessionManager { } else { session.timeListening = sessionJson.timeListening session.updatedAt = sessionJson.updatedAt + session.date = date.format(new Date(), 'YYYY-MM-DD') + session.dayOfWeek = date.format(new Date(), 'dddd') await this.db.updateEntity('session', session) }