Skip to content

Commit

Permalink
feat: add 12-hour time format in printers overview
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Dej <[email protected]>
  • Loading branch information
meteyou committed Sep 27, 2023
1 parent 890b996 commit 01edc5b
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/store/farm/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const getters: GetterTree<FarmPrinterState, any> = {
return []
},

getPrinterPreview: (state, getters) => {
getPrinterPreview: (state, getters, rootState, rootGetters) => {
if (!state.server.klippy_connected) return []

const output = []
Expand Down Expand Up @@ -215,19 +215,28 @@ export const getters: GetterTree<FarmPrinterState, any> = {
})
}

if (
'print_stats' in state.data &&
'state' in state.data.print_stats &&
state.data.print_stats.state === 'printing' &&
getters['getPrintPercent'] > 0
) {
if ((state.data?.print_stats?.state ?? '') === 'printing' && getters['getPrintPercent'] > 0) {
const hours12Format = rootGetters['gui/getHours12Format'] ?? false
const eta = new Date(getters.estimated_time_eta)
const h = eta.getHours() >= 10 ? eta.getHours() : '0' + eta.getHours()
const m = eta.getMinutes() >= 10 ? eta.getMinutes() : '0' + eta.getMinutes()

const date = new Date(eta)
let am = true
let h: string | number = date.getHours()

if (hours12Format && h > 11) am = false
if (hours12Format && h > 12) h -= 12
if (h < 10) h = '0' + h

const m = date.getMinutes() >= 10 ? date.getMinutes() : '0' + date.getMinutes()

const diff = date.getTime() - new Date().getTime()
let outputOutput = h + ':' + m
if (hours12Format) outputOutput += ` ${am ? 'AM' : 'PM'}`
if (diff > 60 * 60 * 24 * 1000) outputOutput += `+${Math.trunc(diff / (60 * 60 * 24 * 1000))}`

output.push({
name: 'ETA',
value: getters.estimated_time_eta > 0 ? h + ':' + m : '--',
value: getters.estimated_time_eta > 0 ? outputOutput : '--',
file: getters.estimated_time_file,
filament: getters.estimated_time_filament,
slicer: getters.estimated_time_slicer,
Expand Down

0 comments on commit 01edc5b

Please sign in to comment.