local _, F = ... F.Utils = {} function F.Utils.Round(num, decimals) local mult = 10^(decimals or 0) return math.floor(num * mult + 0.5) / mult end -- Format large numbers into readable strings (commas or K/M suffixes) function F.Utils.FormatLargeNumber(n) n = tonumber(n) or 0 if n >= 1000000 then return F.Utils.Round(n / 1000000, 1) .. "M" elseif n >= 1000 then -- Insert thousands separators (commas) local s = tostring(math.floor(n)) local k repeat s, k = s:gsub("^(-?%d+)(%d%d%d)", "%1,%2") until k == 0 return s else return tostring(n) end end FormatLargeNumber = function(n) return F.Utils.FormatLargeNumber(n) end function F.Utils.FormatTime(time, formatString) if time <= 59 then return "< 1m" end local d = math.floor(time / 86400) local h = math.floor((time % 86400) / 3600) local m = math.floor((time % 3600) / 60) local s = time % 60 local t = formatString or "%dd %hh %mm" local pad = function(v) return v < 10 and "0" .. v or v end local subs = { ["%%D([Dd]?)"] = d > 0 and (pad(d) .. "%1") or "", ["%%d([Dd]?)"] = d > 0 and (d .. "%1") or "", ["%%H([Hh]?)"] = (d > 0 or h > 0) and (pad(h) .. "%1") or "", ["%%h([Hh]?)"] = (d > 0 or h > 0) and (h .. "%1") or "", ["%%M([Mm]?)"] = pad(m) .. "%1", ["%%m([Mm]?)"] = m .. "%1", } for k,v in pairs(subs) do t = t:gsub(k, v) end return strtrim(t:gsub("^%s*0*", ""):gsub("^%s*[DdHhMm]", ""), " :/-|") end