Refined the convertTime function
This commit is contained in:
parent
d2cc8c5573
commit
bc31a30a66
3 changed files with 57 additions and 15 deletions
|
@ -183,3 +183,8 @@ Update 27/02/2022 18:30 UTC
|
||||||
* `settings.notyf.updateCider.update-timeout`: 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-downloaded`: Added for `en_US`
|
||||||
* `settings.notyf.updateCider.update-error`: Added for `en_US`
|
* `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`
|
|
@ -89,6 +89,8 @@
|
||||||
"term.time.added": "Added",
|
"term.time.added": "Added",
|
||||||
"term.time.released": "Released",
|
"term.time.released": "Released",
|
||||||
"term.time.updated": "Updated",
|
"term.time.updated": "Updated",
|
||||||
|
"term.time.days": "days",
|
||||||
|
"term.time.day": "day",
|
||||||
"term.time.hours": "hours",
|
"term.time.hours": "hours",
|
||||||
"term.time.hour": "hour",
|
"term.time.hour": "hour",
|
||||||
"term.time.minutes": "minutes",
|
"term.time.minutes": "minutes",
|
||||||
|
|
|
@ -1334,24 +1334,65 @@ const app = new Vue({
|
||||||
return this.playerLCD.playbackDuration
|
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") {
|
if (typeof time !== "number") {
|
||||||
time = parseInt(time)
|
time = parseInt(time)
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeGates = {
|
const timeGates = {
|
||||||
600: 15,
|
600: 15, // 10 Minutes
|
||||||
3600: 14,
|
3600: 14, // Hour
|
||||||
36000: 12,
|
36000: 12, // 10 Hours
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const datetime = new Date(time * 1000)
|
||||||
|
|
||||||
|
let returnTime = datetime.toISOString().substring(11, 19);
|
||||||
for (let key in timeGates) {
|
for (let key in timeGates) {
|
||||||
if (time < key) {
|
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) {
|
hashCode(str) {
|
||||||
let hash = 0,
|
let hash = 0,
|
||||||
|
@ -2314,14 +2355,8 @@ const app = new Vue({
|
||||||
getTotalTime() {
|
getTotalTime() {
|
||||||
try {
|
try {
|
||||||
if (app.showingPlaylist.relationships.tracks.data.length > 0) {
|
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);
|
const timeInSeconds = Math.round([].concat(...app.showingPlaylist.relationships.tracks.data).reduce((a, {attributes: {durationInMillis}}) => a + durationInMillis, 0) / 1000);
|
||||||
let hours = Math.floor(time / 3600)
|
return `${app.showingPlaylist.relationships.tracks.data.length} ${app.getLz('term.tracks', options = {count: app.showingPlaylist.relationships.tracks.data.length})}, ${this.convertTime(timeInSeconds, 'long')}`
|
||||||
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}) + ".");
|
|
||||||
} else return ""
|
} else return ""
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return ""
|
return ""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue