Added support for days
This commit is contained in:
@@ -83,23 +83,32 @@ end
|
||||
|
||||
|
||||
function format_time_custom(seconds)
|
||||
local h = math.floor(seconds / 3600)
|
||||
local d = math.floor(seconds / 86400)
|
||||
local h = math.floor((seconds % 86400) / 3600)
|
||||
local m = math.floor((seconds % 3600) / 60)
|
||||
local s = seconds % 60
|
||||
local fmt = format_string or "{h}:{m}:{s}"
|
||||
-- Zero-padded
|
||||
local dd = string.format("%02d", d)
|
||||
local hh = string.format("%02d", h)
|
||||
local mm = string.format("%02d", m)
|
||||
local ss = string.format("%02d", s)
|
||||
-- Non-padded
|
||||
local D = tostring(d)
|
||||
local H = tostring(h)
|
||||
local M = tostring(m)
|
||||
local S = tostring(s)
|
||||
|
||||
-- Smart removal for non-padded units
|
||||
-- Remove '0h' or '0h ' or '0h,' etc. if h == 0
|
||||
if d == 0 then
|
||||
fmt = fmt:gsub("0d[ ,]*", "")
|
||||
fmt = fmt:gsub("0d", "")
|
||||
fmt = fmt:gsub("0D[ ,]*", "")
|
||||
fmt = fmt:gsub("0D", "")
|
||||
fmt = fmt:gsub("{D}d[ ,]*", "")
|
||||
fmt = fmt:gsub("{D}d", "")
|
||||
end
|
||||
if h == 0 then
|
||||
-- Remove patterns like '0h ', '0h,', '0h', '0h\n', etc.
|
||||
fmt = fmt:gsub("0h[ ,]*", "")
|
||||
fmt = fmt:gsub("0h", "")
|
||||
fmt = fmt:gsub("0H[ ,]*", "")
|
||||
@@ -116,9 +125,11 @@ function format_time_custom(seconds)
|
||||
fmt = fmt:gsub("{M}m", "")
|
||||
end
|
||||
-- Replace placeholders
|
||||
fmt = fmt:gsub("{d}", dd)
|
||||
fmt = fmt:gsub("{h}", hh)
|
||||
fmt = fmt:gsub("{m}", mm)
|
||||
fmt = fmt:gsub("{s}", ss)
|
||||
fmt = fmt:gsub("{D}", d ~= 0 and D or "")
|
||||
fmt = fmt:gsub("{H}", h ~= 0 and H or "")
|
||||
fmt = fmt:gsub("{M}", m ~= 0 and M or "")
|
||||
fmt = fmt:gsub("{S}", S)
|
||||
|
Reference in New Issue
Block a user