mNo edit summary |
No edit summary |
||
(11 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
+ | |||
− | |||
function p.d(time) |
function p.d(time) |
||
− | + | if not time or time == 0 or time == '' then |
|
⚫ | |||
+ | end |
||
⚫ | |||
+ | seconds = tonumber(time) % 60 |
||
+ | if seconds == 1 then |
||
+ | result = '1 second' |
||
+ | elseif seconds ~= 0 then |
||
+ | result = seconds .. ' seconds' |
||
+ | end |
||
time = (time - time % 60) / 60 |
time = (time - time % 60) / 60 |
||
− | + | minutes = time % 60 |
|
+ | if result:len() and minutes ~= 0 then |
||
⚫ | |||
⚫ | |||
end |
end |
||
− | if |
+ | if minutes == 1 then |
− | result = ' |
+ | result = '1 minute' .. result |
+ | elseif minutes ~= 0 then |
||
+ | result = minutes .. ' minutes' .. result |
||
end |
end |
||
− | result = tostring(time % 60) .. ':' .. result |
||
time = (time - time % 60) / 60 |
time = (time - time % 60) / 60 |
||
− | + | total_hours = time |
|
− | + | hours = time % 24 |
|
+ | if result:len() and hours ~= 0 then |
||
⚫ | |||
end |
end |
||
+ | days = (time - time % 24) / 24 |
||
⚫ | |||
− | + | result_2 = result |
|
+ | if total_hours == 1 then |
||
+ | result_2 = '1 hour' .. result_2 |
||
+ | elseif total_hours ~= 0 then |
||
+ | result_2 = total_hours .. ' hours' .. result_2 |
||
end |
end |
||
+ | if hours == 1 then |
||
− | result = tostring(time % 24) .. ':' .. result |
||
− | + | result = '1 hour' .. result |
|
− | + | elseif hours ~= 0 then |
|
− | + | result = hours .. ' hours' .. result |
|
end |
end |
||
− | if |
+ | if days == 0 then |
− | + | return result_2 |
|
+ | elseif days == 1 then |
||
+ | return result_2 .. '<br />(' .. '1 day ' .. result .. ')' |
||
+ | else |
||
+ | return result_2 .. '<br />(' .. days .. ' days ' .. result .. ')' |
||
end |
end |
||
⚫ | |||
end |
end |
||
+ | |||
− | |||
+ | function p.fd(frame) |
||
+ | return p.d(frame.args[1]) |
||
+ | end |
||
+ | |||
+ | function p.r(inverse_rarity) |
||
+ | inverse_rarity = tonumber(inverse_rarity) |
||
+ | if inverse_rarity == 1 then |
||
+ | return "always" |
||
+ | elseif inverse_rarity < 12 then |
||
+ | return "common" |
||
+ | elseif inverse_rarity < 32 then |
||
+ | return "uncommon" |
||
+ | elseif inverse_rarity < 62 then |
||
+ | return "rare" |
||
+ | else |
||
+ | return "very-rare" |
||
+ | end |
||
+ | end |
||
+ | |||
function p.c(number) |
function p.c(number) |
||
− | + | local result = tostring(number), k |
|
+ | while true do |
||
− | return number:reverse():gsub('(%d%d%d)','%1,', (number:len() - 1) / 3):reverse() |
||
+ | result, k = result:gsub("^(-?%d+)(%d%d%d)", '%1,%2') |
||
+ | if k == 0 then |
||
+ | break |
||
+ | end |
||
+ | end |
||
+ | return result |
||
+ | end |
||
+ | |||
+ | function p.fc(frame) |
||
+ | return p.c(frame.args[1]) |
||
end |
end |
||
+ | |||
− | |||
function p.pp(frame) |
function p.pp(frame) |
||
return frame:preprocess(frame.args[1]) |
return frame:preprocess(frame.args[1]) |
||
end |
end |
||
+ | |||
− | |||
return p |
return p |
Latest revision as of 17:42, 31 January 2021
Documentation for this module may be created at Module:Util/doc
local p = {}
function p.d(time)
if not time or time == 0 or time == '' then
return ''
end
result = ''
seconds = tonumber(time) % 60
if seconds == 1 then
result = '1 second'
elseif seconds ~= 0 then
result = seconds .. ' seconds'
end
time = (time - time % 60) / 60
minutes = time % 60
if result:len() and minutes ~= 0 then
result = ' ' .. result
end
if minutes == 1 then
result = '1 minute' .. result
elseif minutes ~= 0 then
result = minutes .. ' minutes' .. result
end
time = (time - time % 60) / 60
total_hours = time
hours = time % 24
if result:len() and hours ~= 0 then
result = ' ' .. result
end
days = (time - time % 24) / 24
result_2 = result
if total_hours == 1 then
result_2 = '1 hour' .. result_2
elseif total_hours ~= 0 then
result_2 = total_hours .. ' hours' .. result_2
end
if hours == 1 then
result = '1 hour' .. result
elseif hours ~= 0 then
result = hours .. ' hours' .. result
end
if days == 0 then
return result_2
elseif days == 1 then
return result_2 .. '<br />(' .. '1 day ' .. result .. ')'
else
return result_2 .. '<br />(' .. days .. ' days ' .. result .. ')'
end
end
function p.fd(frame)
return p.d(frame.args[1])
end
function p.r(inverse_rarity)
inverse_rarity = tonumber(inverse_rarity)
if inverse_rarity == 1 then
return "always"
elseif inverse_rarity < 12 then
return "common"
elseif inverse_rarity < 32 then
return "uncommon"
elseif inverse_rarity < 62 then
return "rare"
else
return "very-rare"
end
end
function p.c(number)
local result = tostring(number), k
while true do
result, k = result:gsub("^(-?%d+)(%d%d%d)", '%1,%2')
if k == 0 then
break
end
end
return result
end
function p.fc(frame)
return p.c(frame.args[1])
end
function p.pp(frame)
return frame:preprocess(frame.args[1])
end
return p