mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
More footer options, default to use icons as prefixes (#5203)
- show icons or letters as prefix of items - various footer separators - progress percentage format with decimal digits - time in 12/24 format - two duration formats (1:30, 1h30') - move some options into Settings submenu
This commit is contained in:
@@ -99,6 +99,91 @@ function util.secondsToClock(seconds, withoutSeconds)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Converts seconds to a period of time string.
|
||||
|
||||
---- @int seconds number of seconds
|
||||
---- @bool withoutSeconds if true 1h30', if false 1h30'10''
|
||||
---- @bool hmsFormat, if true format 1h30m10s
|
||||
---- @treturn string clock string in the form of 1h30' or 1h30'10''
|
||||
function util.secondsToHClock(seconds, withoutSeconds, hmsFormat)
|
||||
seconds = tonumber(seconds)
|
||||
if seconds == 0 then
|
||||
if withoutSeconds then
|
||||
if hmsFormat then
|
||||
return T(_("%1m"), "0")
|
||||
else
|
||||
return "0'"
|
||||
end
|
||||
else
|
||||
if hmsFormat then
|
||||
return T(_("%1s"), "0")
|
||||
else
|
||||
return "0''"
|
||||
end
|
||||
end
|
||||
elseif seconds < 60 then
|
||||
if withoutSeconds and seconds < 30 then
|
||||
if hmsFormat then
|
||||
return T(_("%1m"), "0")
|
||||
else
|
||||
return "0'"
|
||||
end
|
||||
elseif withoutSeconds and seconds >= 30 then
|
||||
if hmsFormat then
|
||||
return T(_("%1m"), "1")
|
||||
else
|
||||
return "1'"
|
||||
end
|
||||
else
|
||||
if hmsFormat then
|
||||
return T(_("%1m%2s"), "0", string.format("%02.f", seconds))
|
||||
else
|
||||
return "0'" .. string.format("%02.f", seconds) .. "''"
|
||||
end
|
||||
end
|
||||
else
|
||||
local round = withoutSeconds and require("optmath").round or math.floor
|
||||
local hours = string.format("%.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("%.f", hours + 1)
|
||||
end
|
||||
if withoutSeconds then
|
||||
if hours == "0" then
|
||||
mins = string.format("%.f", round(seconds / 60))
|
||||
return mins .. "'"
|
||||
end
|
||||
return T(_("%1h%2"), hours, mins)
|
||||
end
|
||||
local secs = string.format("%02.f", math.floor(seconds - hours * 3600 - mins * 60))
|
||||
if hours == "0" then
|
||||
mins = string.format("%.f", round(seconds / 60))
|
||||
if hmsFormat then
|
||||
return T(_("%1m%2s"), mins, secs)
|
||||
else
|
||||
return mins .. "'" .. secs .. "''"
|
||||
end
|
||||
end
|
||||
if hmsFormat then
|
||||
if secs == "00" then
|
||||
return T(_("%1h%2m"), hours, mins)
|
||||
else
|
||||
return T(_("%1h%2m%3s"), hours, mins, secs)
|
||||
end
|
||||
|
||||
else
|
||||
if secs == "00" then
|
||||
return T(_("%1h%2'"), hours, mins)
|
||||
else
|
||||
return T(_("%1h%2'%3''"), hours, mins, secs)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[--
|
||||
Compares values in two different tables.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user