Module:SecondsToTime: Difference between revisions
From IdleOn MMO Wiki
Kiokurashi (talk | contribs) (Created page with "local t = {} function Main(frame) local totsec = frame.args.Time local seconds = totsec local ret = '' if seconds >= 86400 then -- Days ret = ret .. math.floor(seconds / 86400) .. "d" seconds = seconds % 86400 end if seconds >= 3600 then -- Hours if totsec > seconds then ret = ret .. " " end ret = ret .. math.floor(seconds / 3600) .. "h" seconds = seconds % 3600 end if seconds >= 60 then -- Minutes if totsec > seconds then ret = ret .. " " end ret...") |
Kiokurashi (talk | contribs) No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local t = {} | local t = {} | ||
function Main(frame) | function t.Main(frame) | ||
local totsec = frame.args.Time | local totsec = tonumber(frame.args.Time) | ||
local seconds = totsec | local seconds = totsec | ||
local ret = '' | local ret = '' | ||
Line 19: | Line 19: | ||
seconds = seconds % 60 | seconds = seconds % 60 | ||
end | end | ||
if seconds > | if seconds > 0 then -- Seconds | ||
if totsec > seconds then ret = ret .. " " end | if totsec > seconds then ret = ret .. " " end | ||
ret = ret .. seconds .. "s" | ret = ret .. seconds .. "s" |
Latest revision as of 14:00, 30 December 2022
Documentation for this module may be created at Module:SecondsToTime/doc
local t = {}
function t.Main(frame)
local totsec = tonumber(frame.args.Time)
local seconds = totsec
local ret = ''
if seconds >= 86400 then -- Days
ret = ret .. math.floor(seconds / 86400) .. "d"
seconds = seconds % 86400
end
if seconds >= 3600 then -- Hours
if totsec > seconds then ret = ret .. " " end
ret = ret .. math.floor(seconds / 3600) .. "h"
seconds = seconds % 3600
end
if seconds >= 60 then -- Minutes
if totsec > seconds then ret = ret .. " " end
ret = ret .. math.floor(seconds / 60) .. "m"
seconds = seconds % 60
end
if seconds > 0 then -- Seconds
if totsec > seconds then ret = ret .. " " end
ret = ret .. seconds .. "s"
end
return ret
end
return t