Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix octoprint timestamp #693

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/components/services/OctoPrint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,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 @@ -27,7 +27,7 @@
class="progress is-primary"
:value="completion"
max="100"
:title="`${state} - ${completion.toFixed()}%, ${toTime(
:title="`${state} - ${completion.toFixed()}%, ${formatTime(
printTimeLeft
)} left`"
>
Expand Down Expand Up @@ -107,9 +107,28 @@ export default {
console.error(e);
}
},
toTime: function (timastamp) {
the-kaustubh marked this conversation as resolved.
Show resolved Hide resolved
return new Date(timastamp * 1000).toTimeString().substring(0, 5);
},
formatTime: function (seconds) {
the-kaustubh marked this conversation as resolved.
Show resolved Hide resolved
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