Skip to content

Commit

Permalink
Fix octoprint timestamp (#693)
Browse files Browse the repository at this point in the history
update octoprint service with timestamp changes
  • Loading branch information
the-kaustubh authored Oct 25, 2024
1 parent 11cdb50 commit ea12ee5
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/components/services/OctoPrint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'">
Expand All @@ -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 }}%
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit ea12ee5

Please sign in to comment.