From 45c6ebaeb685ba4ed402353ec3de95719d0c6a7e Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sun, 20 Nov 2011 17:44:04 +0100 Subject: [PATCH] bat: fix time calculation, bug introduced in 350e924 --- widgets/bat.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/widgets/bat.lua b/widgets/bat.lua index 2f93518..cf953a9 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -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