Anonymous user
Module:Age: Difference between revisions
update from sandbox: prefix=TEXT inserts TEXT before visible result but after any sort key, with space appended to TEXT if it is more than one character
(update from sandbox: can spell ages using age_generic with format=cardinal + format=ordinal and more) |
(update from sandbox: prefix=TEXT inserts TEXT before visible result but after any sort key, with space appended to TEXT if it is more than one character) |
||
Line 115:
options.ordinal -- true: 'first' instead of 'one'
) or number
end
local function makeExtra(args, flagCurrent)
-- Return extra text that will be inserted before the visible result
-- but after any sort key.
local extra = args.prefix or ''
if mw.ustring.len(extra) > 1 then
-- Parameter "~" gives "~3" whereas "over" gives "over 3".
extra = extra .. ' '
end
if flagCurrent then
extra = '<span class="currentage"></span>' .. extra
end
return extra
end
Line 121 ⟶ 135:
-- Assume value is a valid number which has not overflowed.
if sortable == 'sortable_table' or sortable == 'sortable_on' or sortable == 'sortable_debug' then
local
if value == 0 then
else
local mag = math.floor(math.log10(math.abs(value)) + 1e-14)
if value > 0 then
else
value = value + 10^(mag+1)
end
end
local lhs, rhs
Line 145 ⟶ 158:
rhs = '♠</span>'
end
return lhs ..
end
end
Line 250 ⟶ 263:
end
end
local
local sortable = translateParameters.sortable[args.sortable]
if sortable then
local value = (date.partial and date.partial.first or date).jdz
end
if show ~= 'hide' then
Line 266 ⟶ 279:
end
end
return (
end
Line 344 ⟶ 357:
end
return
(options.
(options.extra or '') ..
sign ..
Line 424 ⟶ 437:
range = parms.range and true or nil,
}
local
if parms.sortable then
local value = diff.age_days + (parms.wantDuration and 1 or 0) -- days and fraction of a day
Line 430 ⟶ 443:
value = -value
end
end
local textOptions = {
suffix = parms.suffix, -- not currently used▼
extra = parms.extra,
format = parms.format,
Line 440 ⟶ 451:
isnegative = diff.isnegative,
range = parms.range,
sortKey = sortKey,
spell = parms.spell,
▲ suffix = parms.suffix, -- not currently used
}
if show.id == 'hide' then
return
end
local values = { diff:age(show.id, diffOptions) }
Line 459 ⟶ 472:
}
return
(textOptions.
makeText({ diff.partial.mindiff:age(show.id, diffOptions) }, show, names[abbr], opt) ..
rangeJoin(textOptions.range) ..
Line 733 ⟶ 746:
abbr = spec.abbr,
disp = spec.disp,
extra = makeExtra(args, getopt.usesCurrent and format ~= 'format_raw')
format = format or spec.format,
round = yes(args.round),
Line 865 ⟶ 878:
local args = frame:getParent().args
local parms = {
extra = makeExtra(args),
wantDuration = yes(args.duration),
range = yes(args.range) or (args.range == 'dash' and 'dash' or nil),
|