diff --git a/src/i18n/README.md b/src/i18n/README.md index de2b2005..525e6f46 100644 --- a/src/i18n/README.md +++ b/src/i18n/README.md @@ -182,4 +182,9 @@ Update 27/02/2022 18:30 UTC * `settings.notyf.updateCider.update-not-available`: Added for `en_US` * `settings.notyf.updateCider.update-timeout`: Added for `en_US` * `settings.notyf.updateCider.update-downloaded`: Added for `en_US` -* `settings.notyf.updateCider.update-error`: Added for `en_US` \ No newline at end of file +* `settings.notyf.updateCider.update-error`: Added for `en_US` + +Update 28/02/2022 13:00 UTC + +* `term.time.days`: Added for `en_US` +* `term.time.day`: Added for `en_US` \ No newline at end of file diff --git a/src/i18n/en_US.json b/src/i18n/en_US.json index eb2230f1..686575d5 100644 --- a/src/i18n/en_US.json +++ b/src/i18n/en_US.json @@ -89,6 +89,8 @@ "term.time.added": "Added", "term.time.released": "Released", "term.time.updated": "Updated", + "term.time.days": "days", + "term.time.day": "day", "term.time.hours": "hours", "term.time.hour": "hour", "term.time.minutes": "minutes", diff --git a/src/renderer/index.js b/src/renderer/index.js index 9018f2c1..767557b5 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -1334,24 +1334,65 @@ const app = new Vue({ return this.playerLCD.playbackDuration } }, - convertTime(time) { + /** + * Converts seconds to dd:hh:mm:ss + * @param time (in seconds) + * @param format (short, long) + * @returns {string} + */ + convertTime(time, format = 'short') { if (typeof time !== "number") { time = parseInt(time) } const timeGates = { - 600: 15, - 3600: 14, - 36000: 12, + 600: 15, // 10 Minutes + 3600: 14, // Hour + 36000: 12, // 10 Hours } + const datetime = new Date(time * 1000) + + let returnTime = datetime.toISOString().substring(11, 19); for (let key in timeGates) { if (time < key) { - return new Date(time * 1000).toISOString().substring(timeGates[key], 19) + returnTime = datetime.toISOString().substring(timeGates[key], 19) + break } } - return new Date(time * 1000).toISOString().substring(11, 19) + // Add the days on the front + let day; + if (time >= 86400) { + day = datetime.toISOString().substring(8, 10) + day = parseInt(day) - 1 + returnTime = day + ":" + returnTime + } + + if (format === 'long') { + const longFormat = [] + + // Seconds + longFormat.push(`${datetime.getSeconds()} ${app.getLz('term.time.second', options = {count: datetime.getSeconds()})}`) + + // Minutes + if (time >= 60) { + longFormat.push(`${datetime.getMinutes()} ${app.getLz('term.time.minute', options = {count: datetime.getMinutes()})}`) + } + + // Hours + if (time >= 3600) { + longFormat.push(`${datetime.getHours()} ${app.getLz('term.time.hour', options = {count: datetime.getHours()})}`) + } + + // Days + if (time >= 86400) { + longFormat.push(`${day} ${app.getLz('term.time.day', options = {count: day})}`) + } + returnTime = longFormat.reverse().join(', ') + } + + return returnTime }, hashCode(str) { let hash = 0, @@ -2314,14 +2355,8 @@ const app = new Vue({ getTotalTime() { try { if (app.showingPlaylist.relationships.tracks.data.length > 0) { - 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 + " " + app.getLz('term.tracks', options = {count: app.showingPlaylist.relationships.tracks.data.length}) + ", " - + ((hours > 0) ? (hours + (" " + (app.getLz('term.time.hour', options = {count: hours}) + ", "))) : "") + - ((mins > 0) ? (mins + (" " + app.getLz('term.time.minute', options = {count: mins}) + ", ")) : "") + - secs + (" " + app.getLz('term.time.second', options = {count: secs}) + "."); + const timeInSeconds = Math.round([].concat(...app.showingPlaylist.relationships.tracks.data).reduce((a, {attributes: {durationInMillis}}) => a + durationInMillis, 0) / 1000); + return `${app.showingPlaylist.relationships.tracks.data.length} ${app.getLz('term.tracks', options = {count: app.showingPlaylist.relationships.tracks.data.length})}, ${this.convertTime(timeInSeconds, 'long')}` } else return "" } catch (err) { return ""