Module:Age/sandbox: Difference between revisions

Content deleted Content added
fix new "currentage" span; do not output it if format=raw used if a calculation needed
format=cardinal and format=ordinal can spell numbers with uppercase/US options
Line 99:
end
return groups:join(',')
end
 
local function spellNumber(number, options, i)
-- Return result of spelling number, or
-- return number (as a string) if cannot spell it.
-- i == 1 for the first number which can optionally start with an uppercase letter.
number = tostring(number)
return require('Module:ConvertNumeric').spell_number(
number,
nil, -- fraction numerator
nil, -- fraction denominator
i == 1 and options.upper, -- true: 'One' instead of 'one'
not options.us, -- true: use 'and' between tens/ones etc
options.adj, -- true: hyphenated
options.ordinal -- true: 'first' instead of 'one'
) or number
end
 
Line 190 ⟶ 206:
debug = 'sortable_debug',
},
}
 
local spellOptions = {
cardinal = {},
Cardinal = { upper = true },
cardinal_us = { us = true },
Cardinal_us = { us = true, upper = true },
ordinal = { ordinal = true },
Ordinal = { ordinal = true, upper = true },
ordinal_us = { ordinal = true, us = true },
Ordinal_us = { ordinal = true, us = true, upper = true },
}
 
Line 247 ⟶ 274:
end
 
local function makeText(values, components, names, options, noUpper)
-- Return wikitext representing an age or duration.
local text = Collection.new()
Line 257 ⟶ 284:
if (islist or v > 0) or (text.n == 0 and i == count) or (text.n > 0 and components.keepZero) then
local fmt, vstr
if i == 1 and options.format == 'format_commas'spell then
fmt = function(number)
return spellNumber(number, options.spell, noUpper or i)
end
elseif i == 1 and options.format == 'format_commas' then
-- Numbers after the first should be small and not need formatting.
fmt = formatNumber
Line 264 ⟶ 295:
end
if islist then
vstr = fmt(v[1]) .. rangeJoin(options.range) .. fmt(v[2])
noUpper = true
vstr = vstr .. fmt(v[2])
else
vstr = fmt(v)
Line 407 ⟶ 440:
isnegative = diff.isnegative,
range = parms.range,
spell = parms.spell,
}
if show.id == 'hide' then
Line 422 ⟶ 456:
join = textOptions.join,
isnegative = textOptions.isnegative,
spell = textOptions.spell,
}
return
Line 427 ⟶ 462:
makeText({ diff.partial.mindiff:age(show.id, diffOptions) }, show, names[abbr], opt) ..
rangeJoin(textOptions.range) ..
makeText({ diff.partial.maxdiff:age(show.id, diffOptions) }, show, names[abbr], opt, true) ..
(textOptions.suffix or '')
end
Line 684 ⟶ 719:
end
local format = stripToNil(args.format)
local spell = spellOptions[format]
if format then
format = 'format_' .. format
Line 702 ⟶ 738:
sep = spec.sep,
sortable = translateParameters.sortable[args.sortable or spec.sortable],
spell = spell,
}
if (spec.negative or frame.args.negative) == 'error' and parms.diff.isnegative then