Only zero is empty, and the last day is worth reading
This commit is contained in:
@@ -293,11 +293,32 @@ function barWidth(cartridge) {
|
||||
return Math.max(0, Math.min(100, level)) + '%'
|
||||
}
|
||||
|
||||
// daysleft is fractional, so the last day of a cartridge's life is readable
|
||||
// instead of collapsing to "empty". Only an actual zero is empty; anything above
|
||||
// it has time left and the row says how much, in whatever unit carries meaning.
|
||||
const HOURS_PER_DAY = 24
|
||||
const MINUTES_PER_HOUR = 60
|
||||
|
||||
function daysText(cartridge) {
|
||||
if (cartridge.daysleft == null) return '-'
|
||||
if (cartridge.daysleft === 0) return 'empty'
|
||||
if (cartridge.daysleft === 1) return '1 day'
|
||||
return cartridge.daysleft + ' days'
|
||||
const days = cartridge.daysleft
|
||||
if (days == null) return '-'
|
||||
if (days <= 0) return 'empty'
|
||||
|
||||
if (days < 1) {
|
||||
const hours = days * HOURS_PER_DAY
|
||||
// Under an hour, hours would round to 0 and read as empty again.
|
||||
if (hours < 1) {
|
||||
const minutes = Math.max(1, Math.round(hours * MINUTES_PER_HOUR))
|
||||
return `${minutes} min`
|
||||
}
|
||||
const rounded = Math.round(hours)
|
||||
return rounded === 1 ? '1 hour' : `${rounded} hours`
|
||||
}
|
||||
|
||||
// Whole days from here. The estimate is not precise enough for "3.7 days" to
|
||||
// mean more than "about 4", and a column of decimals is harder to scan.
|
||||
const rounded = Math.round(days)
|
||||
return rounded === 1 ? '1 day' : `${rounded} days`
|
||||
}
|
||||
|
||||
function orderKey(item) {
|
||||
|
||||
Reference in New Issue
Block a user