Last active
March 27, 2019 23:39
-
-
Save Srlion/a9c43a88d65f0bcba5957f903066b0ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local times = {"w", 604800, "d", 86400, "h", 3600, "m", 60, "s", 1} | |
for i = 1, # times - 2, 2 do | |
times[i] = times[i] .. (" ") | |
end | |
local math_floor = math.floor | |
function FormatTime(seconds) | |
if (seconds <= 0) then | |
return seconds .. "s" | |
end | |
local str = "" | |
for i = 1, # times, 2 do | |
local n1, n2 = times[i + 1] | |
n2, seconds = math_floor(seconds / n1), seconds % n1 | |
if (n2 > 0) then | |
str = str .. (n2 .. times[i]) | |
elseif (n1 == 1 && seconds > 0) then | |
str = str .. (seconds .. times[i]) | |
end | |
end | |
return str | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment