Module:Age: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(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: | Line 115: | ||
options.ordinal -- true: 'first' instead of 'one' |
options.ordinal -- true: 'first' instead of 'one' |
||
) or number |
) 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 |
end |
||
Line 121: | Line 135: | ||
-- Assume value is a valid number which has not overflowed. |
-- Assume value is a valid number which has not overflowed. |
||
if sortable == 'sortable_table' or sortable == 'sortable_on' or sortable == 'sortable_debug' then |
if sortable == 'sortable_table' or sortable == 'sortable_on' or sortable == 'sortable_debug' then |
||
local |
local sortKey |
||
if value == 0 then |
if value == 0 then |
||
sortKey = '5000000000000000000' |
|||
else |
else |
||
local mag = math.floor(math.log10(math.abs(value)) + 1e-14) |
local mag = math.floor(math.log10(math.abs(value)) + 1e-14) |
||
local prefix |
|||
if value > 0 then |
if value > 0 then |
||
sortKey = 7000 + mag |
|||
else |
else |
||
sortKey = 2999 - mag |
|||
value = value + 10^(mag+1) |
value = value + 10^(mag+1) |
||
end |
end |
||
sortKey = string.format('%d', sortKey) .. string.format('%015.0f', math.floor(value * 10^(14-mag))) |
|||
end |
end |
||
local lhs, rhs |
local lhs, rhs |
||
Line 145: | Line 158: | ||
rhs = '♠</span>' |
rhs = '♠</span>' |
||
end |
end |
||
return lhs .. |
return lhs .. sortKey .. rhs |
||
end |
end |
||
end |
end |
||
Line 250: | Line 263: | ||
end |
end |
||
end |
end |
||
local |
local sortKey, result |
||
local sortable = translateParameters.sortable[args.sortable] |
local sortable = translateParameters.sortable[args.sortable] |
||
if sortable then |
if sortable then |
||
local value = (date.partial and date.partial.first or date).jdz |
local value = (date.partial and date.partial.first or date).jdz |
||
sortKey = makeSort(value, sortable) |
|||
end |
end |
||
if show ~= 'hide' then |
if show ~= 'hide' then |
||
Line 266: | Line 279: | ||
end |
end |
||
end |
end |
||
return ( |
return (sortKey or '') .. (result or '') |
||
end |
end |
||
Line 344: | Line 357: | ||
end |
end |
||
return |
return |
||
(options. |
(options.sortKey or '') .. |
||
(options.extra or '') .. |
(options.extra or '') .. |
||
sign .. |
sign .. |
||
Line 424: | Line 437: | ||
range = parms.range and true or nil, |
range = parms.range and true or nil, |
||
} |
} |
||
local |
local sortKey |
||
if parms.sortable then |
if parms.sortable then |
||
local value = diff.age_days + (parms.wantDuration and 1 or 0) -- days and fraction of a day |
local value = diff.age_days + (parms.wantDuration and 1 or 0) -- days and fraction of a day |
||
Line 430: | Line 443: | ||
value = -value |
value = -value |
||
end |
end |
||
sortKey = makeSort(value, parms.sortable) |
|||
end |
end |
||
local textOptions = { |
local textOptions = { |
||
prefix = prefix, |
|||
⚫ | |||
extra = parms.extra, |
extra = parms.extra, |
||
format = parms.format, |
format = parms.format, |
||
Line 440: | Line 451: | ||
isnegative = diff.isnegative, |
isnegative = diff.isnegative, |
||
range = parms.range, |
range = parms.range, |
||
sortKey = sortKey, |
|||
spell = parms.spell, |
spell = parms.spell, |
||
⚫ | |||
} |
} |
||
if show.id == 'hide' then |
if show.id == 'hide' then |
||
return |
return sortKey or '' |
||
end |
end |
||
local values = { diff:age(show.id, diffOptions) } |
local values = { diff:age(show.id, diffOptions) } |
||
Line 459: | Line 472: | ||
} |
} |
||
return |
return |
||
(textOptions. |
(textOptions.sortKey or '') .. |
||
makeText({ diff.partial.mindiff:age(show.id, diffOptions) }, show, names[abbr], opt) .. |
makeText({ diff.partial.mindiff:age(show.id, diffOptions) }, show, names[abbr], opt) .. |
||
rangeJoin(textOptions.range) .. |
rangeJoin(textOptions.range) .. |
||
Line 733: | Line 746: | ||
abbr = spec.abbr, |
abbr = spec.abbr, |
||
disp = spec.disp, |
disp = spec.disp, |
||
extra = (getopt.usesCurrent and format ~= 'format_raw') |
extra = makeExtra(args, getopt.usesCurrent and format ~= 'format_raw'), |
||
format = format or spec.format, |
format = format or spec.format, |
||
round = yes(args.round), |
round = yes(args.round), |
||
Line 865: | Line 878: | ||
local args = frame:getParent().args |
local args = frame:getParent().args |
||
local parms = { |
local parms = { |
||
extra = makeExtra(args), |
|||
wantDuration = yes(args.duration), |
wantDuration = yes(args.duration), |
||
range = yes(args.range) or (args.range == 'dash' and 'dash' or nil), |
range = yes(args.range) or (args.range == 'dash' and 'dash' or nil), |