Module:Ordinal: Difference between revisions

Remove sup argument (depended on yesno module which we chose not to import)
Ganaram inukshuk (talk | contribs)
remove comments referring to nonexistent pages
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
--[[ 
This template will add the appropriate ordinal suffix to a given integer.
Please do not modify this code without applying the changes first at
Module:Ordinal/sandbox and testing.
]]
local p = {}
local p = {}


--[[
--[[
This function converts an integer value into a numeral followed by ordinal indicator.
This function converts an integer value into a numeral followed by ordinal indicator.
The output string might contain HTML tags.
The output string might contain HTML tags.
 
Usage:
Usage:
{{#invoke:Ordinal|ordinal|1=|2=}}
{{#invoke: Ordinal|ordinal|1=|2=}}
{{#invoke:Ordinal|ordinal}} - uses the caller's parameters
{{#invoke: Ordinal|ordinal}} - uses the caller's parameters
 
Parameters
Parameters
    1: Any number or string.
    1: Any number or string.
    2: Set to "d" if the module should display "d" instead of "nd" and "rd".
    2: Set to "d" if the module should display "d" instead of "nd" and "rd".
]]
]]
function p.ordinal(frame)
function p.ordinal(frame)
local args = frame.args
local args = frame.args
    if args[1] == nil then
if args[1] == nil then
        args = frame:getParent().args
args = frame:getParent().args
    end
end
    if args[1] == nil then
if args[1] == nil then
    args[1] = "{{{1}}}"
args[1] = "{{{1}}}"
    end
end
    return p._ordinal(args[1], (args[2] == 'd'))
return p._ordinal(args[1], (args[2] == "d"))
end
end


Line 40: Line 31:
local mod10 = math.abs(x) % 10
local mod10 = math.abs(x) % 10
local mod100 = math.abs(x) % 100
local mod100 = math.abs(x) % 100
if     mod10 == 1 and mod100 ~= 11 then
if mod10 == 1 and mod100 ~= 11 then
suffix = "st"
suffix = "st"
elseif mod10 == 2 and mod100 ~= 12 then
elseif mod10 == 2 and mod100 ~= 12 then
if d then suffix = "d" else suffix = "nd" end
if d then
suffix = "d"
else
suffix = "nd"
end
elseif mod10 == 3 and mod100 ~= 13 then
elseif mod10 == 3 and mod100 ~= 13 then
if d then suffix = "d" else suffix = "rd" end
if d then
suffix = "d"
else
suffix = "rd"
end
end
end
end
end