bat: fix time calculation, bug introduced in 350e924

This commit is contained in:
Adrian C. (anrxc) 2011-11-20 17:44:04 +01:00
parent cd4b04df44
commit 45c6ebaeb6
1 changed files with 6 additions and 2 deletions

View File

@ -10,6 +10,7 @@ local string = { format = string.format }
local helpers = require("vicious.helpers")
local math = {
min = math.min,
max = math.max,
floor = math.floor
}
-- }}}
@ -65,6 +66,7 @@ local function worker(format, warg)
-- Calculate remaining (charging or discharging) time
local time = "N/A"
if tonumber(rate) then
if state == "+" then
timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
@ -73,9 +75,11 @@ local function worker(format, warg)
else
return {state, percent, time}
end
-- Calculate time (but work around broken BAT/ACPI implementations)
local hoursleft = math.min(math.floor(timeleft), 0)
local minutesleft = math.min(math.floor((timeleft - hoursleft) * 60 ), 0)
local hoursleft = math.max(math.floor(timeleft), 0)
local minutesleft = math.max(math.floor((timeleft - hoursleft) * 60 ), 0)
time = string.format("%02d:%02d", hoursleft, minutesleft)
end