mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
[fix] util.secondsToClock 00:60 should be 01:00 (#3371)
This commit is contained in:
@@ -75,18 +75,22 @@ function util.secondsToClock(seconds, withoutSeconds)
|
||||
seconds = tonumber(seconds)
|
||||
if seconds == 0 or seconds ~= seconds then
|
||||
if withoutSeconds then
|
||||
return "00:00";
|
||||
return "00:00"
|
||||
else
|
||||
return "00:00:00";
|
||||
return "00:00:00"
|
||||
end
|
||||
else
|
||||
local round = withoutSeconds and require("optmath").round or math.floor
|
||||
local hours = string.format("%02.f", math.floor(seconds / 3600));
|
||||
local mins = string.format("%02.f", round(seconds / 60 - (hours * 60)));
|
||||
local hours = string.format("%02.f", math.floor(seconds / 3600))
|
||||
local mins = string.format("%02.f", round(seconds / 60 - (hours * 60)))
|
||||
if mins == "60" then
|
||||
mins = string.format("%02.f", 0)
|
||||
hours = string.format("%02.f", hours + 1)
|
||||
end
|
||||
if withoutSeconds then
|
||||
return hours .. ":" .. mins
|
||||
end
|
||||
local secs = string.format("%02.f", math.floor(seconds - hours * 3600 - mins * 60));
|
||||
local secs = string.format("%02.f", math.floor(seconds - hours * 3600 - mins * 60))
|
||||
return hours .. ":" .. mins .. ":" .. secs
|
||||
end
|
||||
end
|
||||
|
||||
@@ -329,6 +329,14 @@ describe("util module", function()
|
||||
util.secondsToClock(110, true))
|
||||
assert.is_equal("00:02",
|
||||
util.secondsToClock(120, true))
|
||||
assert.is_equal("01:00",
|
||||
util.secondsToClock(3600, true))
|
||||
assert.is_equal("01:00",
|
||||
util.secondsToClock(3599, true))
|
||||
assert.is_equal("01:00",
|
||||
util.secondsToClock(3570, true))
|
||||
assert.is_equal("00:59",
|
||||
util.secondsToClock(3569, true))
|
||||
end)
|
||||
it("should convert seconds to 00:00:00 format", function()
|
||||
assert.is_equal("00:00:00",
|
||||
|
||||
Reference in New Issue
Block a user