Module:Common: Difference between revisions

no edit summary
No edit summary
No edit summary
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 days, ', s/ONE_DAY) .. os.date("!%X", s)
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
432

edits