Fix octoprint timestamp (#693)

update octoprint service with timestamp changes
This commit is contained in:
Kaustubh Murumkar 2024-10-26 01:09:21 +05:30 committed by GitHub
parent 11cdb50ea5
commit ea12ee520b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,9 +12,9 @@
<i class="fa-solid fa-gear mr-1"></i>
<b v-if="completion">{{ completion.toFixed() }}%</b>
<span class="separator mx-1"> | </span>
<span v-if="printTime" :title="`${toTime(printTimeLeft)} left`">
<span v-if="printTime" :title="`${formatTime(printTimeLeft)} left`">
<i class="fa-solid fa-stopwatch mr-1"></i>
{{ toTime(printTime) }}
{{ formatTime(printTime) }}
</span>
</template>
<template v-if="!error && display == 'text' && statusClass == 'ready'">
@ -33,8 +33,8 @@
class="progress is-primary"
:value="completion"
max="100"
:title="`${state} - ${completion.toFixed()}%, ${toTime(
printTimeLeft,
:title="`${state} - ${completion.toFixed()}%, ${formatTime(
printTimeLeft
)} left`"
>
{{ completion }}%
@ -115,9 +115,28 @@ export default {
console.error(e);
}
},
toTime: function (timastamp) {
return new Date(timastamp * 1000).toTimeString().substring(0, 5);
},
formatTime: function (seconds) {
const days = Math.floor(seconds / 86400);
let remainingSeconds = seconds % 86400;
const hours = Math.floor(remainingSeconds / 3600);
remainingSeconds %= 3600;
const minutes = Math.floor(remainingSeconds / 60);
const secs = remainingSeconds % 60;
const formattedHrs = hours.toString().padStart(2, '0')
const formattedMins = minutes.toString().padStart(2, '0')
const formattedSecs = secs.toString().padStart(2, '0')
if (days > 0) {
return `${days}d ${formattedHrs}h ${formattedMins}m`;
} else if (hours > 0) {
return `${formattedHrs}h ${formattedMins}m ${formattedSecs}s`;
} else if (minutes > 0) {
return `${formattedMins}m ${formattedSecs}s`;
} else {
return `${secs} seconds`;
}
}
},
};
</script>