432
edits
No edit summary |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 278: | Line 278: | ||
local ONE_DAY = 24 * 60 * 60 | local ONE_DAY = 24 * 60 * 60 | ||
if s > ONE_DAY then | if s > ONE_DAY then | ||
return string.format('%d | return string.format('%d day%s, ', s/ONE_DAY, (math.floor(s/ONE_DAY) > 1) and "s" or "") .. os.date("!%X", s) | ||
else | else | ||
return os.date("!%X", s) | return os.date("!%X", s) | ||
Line 315: | Line 315: | ||
function p.testSecondsToHuman(s) | function p.testSecondsToHuman(s) | ||
output = {} | output = {} | ||
for i, s in ipairs({-1, 0, 0.5, 5 * 60, 5 * 60 + 20, 6 * 60 * 60, 6 * 60 * 60 + 20, 6 * 60 * 60 + 3 * 60 + 20, 1 * 24 * 60 * 60, 2 * 24 * 60 * 60 + 3 * 60 * 60 + 2 * 60 + 1}) do | for i, s in ipairs( | ||
{-1, 0, 0.5, 5 * 60, 5 * 60 + 20, | |||
6 * 60 * 60, 6 * 60 * 60 + 20, 6 * 60 * 60 + 3 * 60 + 20, | |||
1 * 24 * 60 * 60, 2 * 24 * 60 * 60 + 3 * 60 * 60 + 2 * 60 + 1}) do | |||
table.insert(output, string.format('%s = %s', s, p.secondsToHuman(s))) | table.insert(output, string.format('%s = %s', s, p.secondsToHuman(s))) | ||
end | end | ||
Line 324: | Line 327: | ||
if frame == nil then | if frame == nil then | ||
return '<invalid frame object>' | return '<invalid frame object>' | ||
end | |||
if frame.args[1] == nil then | |||
return '<missing argument seconds>' | |||
end | end | ||
local seconds = tonumber(frame.args[1]) | local seconds = tonumber(frame.args[1]) | ||
if frame.args["hms"] = | if frame.args["hms"] ~= "" then | ||
return p.secondsToHMS(seconds) | |||
else | |||
return p.secondsToHuman(seconds) | return p.secondsToHuman(seconds) | ||
end | end | ||
end | end | ||
return p | return p |
edits