diff --git a/widgets/bat_openbsd.lua b/widgets/bat_openbsd.lua index 15b7598..752a666 100644 --- a/widgets/bat_openbsd.lua +++ b/widgets/bat_openbsd.lua @@ -3,14 +3,9 @@ local setmetatable = setmetatable local tonumber = tonumber local string = { format = string.format, gmatch = string.gmatch } local io = { popen = io.popen } -local math = { floor = math.floor } -local helpers = require("vicious.helpers") -local string = { - gmatch = string.gmatch, - match = string.match, - format = string.format -} +local math = { floor = math.floor, modf = math.modf } -- }}} + local bat_openbsd = {} local function worker(format, warg) @@ -43,10 +38,10 @@ local function worker(format, warg) if tonumber(bat_info.power0) < 1 then time = "∞" else - local raw_time = bat_info.watthour3 / bat_info.power0 - local hours = math.floor(raw_time) - local minutes = raw_time % 1 - time = string.format("%d:%0.2d", hours, minutes) + local raw_time = bat_info.watthour3 / bat_info.power0 + local hours, hour_fraction = math.modf(raw_time) + local minutes = math.floor(60 * hour_fraction) + time = string.format("%d:%0.2d", hours, minutes) end -- calculate wear level from (last full / design) capacity