Anonymous

Module:Common: Difference between revisions

From Melvor Idle
no edit summary
(Add getEquipmentSlotLink function)
No edit summary
Line 271: Line 271:
else
else
return table.concat(reqArray, '<br/>')
return table.concat(reqArray, '<br/>')
end
end
-- 123 => 00:02:03
function p.secondsToHMS(s)
local ONE_DAY = 24 * 60 * 60
if s > ONE_DAY then
return string.format('%d days, ', s/ONE_DAY) .. os.date("!%X", s)
else
return os.date("!%X", s)
end
end
-- 123 => 2 minutes, 3 seconds
function p.secondsToHuman(s)
if s < 60 then
if s > 0 or s < 0 then
return string.format('%.1f seconds', s)
else
return string.format('0 seconds', s)
end
end
local days = math.floor(s / (24 * 60 * 60))
local hours = math.floor(s / (60 * 60) % (24))
local minutes = math.floor(s / 60 % 60)
local seconds = math.floor(s % (60))
local output = {}
if days > 0 then
table.insert(output, string.format('%d day%s', days, (days > 1) and "s" or ""))
end
if hours > 0 then
table.insert(output, string.format('%d hour%s', hours, (hours > 1) and "s" or ""))
end
if minutes > 0 then
table.insert(output, string.format('%d minute%s', minutes, (minutes > 1) and "s" or ""))
end
if seconds > 0 then
table.insert(output, string.format('%d second%s', seconds, (seconds > 1) and "s" or ""))
end
return table.concat(output, ", ")
end
function p.testSecondsToHuman(s)
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
table.insert(output, string.format('%s = %s', s, p.secondsToHuman(s)))
end
return table.concat(output, ' || ')
end
function p.prettyPrintTime(frame)
if frame == nil then
return '<invalid frame object>'
end
local seconds = tonumber(frame.args[1])
if frame.args["hms"] == nil then
return p.secondsToHuman(seconds)
else
return p.secondsToHMS(seconds)
end
end
end
end


return p
return p
432

edits