Module:Age: Difference between revisions

1,005 bytes added ,  6 years ago
update from sandbox with features discussed at Template talk:Age
m (Changed protection level for "Module:Age": that was weird ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)))
(update from sandbox with features discussed at Template talk:Age)
Line 312:
return
(options.prefix or '') ..
(options.extra or '') ..
sign ..
text:join() ..
Line 401 ⟶ 402:
prefix = prefix,
suffix = parms.suffix, -- not currently used
extra = parms.extra,
format = parms.format,
join = parms.sep or defaultJoin,
Line 443 ⟶ 445:
local Date, currentDate = getExports(frame)
getopt = getopt or {}
local function flagCurrent(text)
-- This allows the calling template to detect if the current date has been used,
-- that is, whether both dates have been entered in a template expecting two.
-- For example, an infobox may want the age when an event occurred, not the current age.
-- Don't bother detecting if wantMixture is used because not needed and it is a poor option.
if not text then
text = 'currentdate'
if getopt.flag == 'usesCurrent' then
getopt.usesCurrent = true
end
end
return text
end
local args = frame:getParent().args
local fields = {}
Line 465 ⟶ 480:
if fields[i] then
imax = i
end
if getopt.omitZero and i % 3 ~= 1 then -- omit zero months and days as unknown values but keep year 0 which is 1 BCE
if tonumber(fields[i]) == 0 then
fields[i] = nil
getopt.partial = true
end
end
end
Line 495 ⟶ 516:
dates[i] = Date(fix, partialText, y, m, d)
elseif not y and not m and not d and not noDefault then
dates[i] = Date('currentdate'flagCurrent())
end
end
Line 501 ⟶ 522:
elseif not noDefault then
getopt.textdates = true -- have parsed each date from a single text field
dates[1] = Date(fix, partialText, flagCurrent(fields[1] or 'currentdate'))
if not getopt.single then
dates[2] = Date(fix, partialText, flagCurrent(fields[2] or 'currentdate'))
end
end
Line 553 ⟶ 574:
show = 'y',
abbr = 'abbr_raw',
flag = 'usesCurrent',
templateomitZero = true,
range = 'no',
},
age_full_years_nts = { -- {{age nts}}
Line 650 ⟶ 674:
local getopt = {
fix = yes(args.fix),
flag = stripToNil(args.flag) or spec.flag,
omitZero = spec.omitZero,
partial = partial,
wantMixture = spec.wantMixture,
Line 671 ⟶ 697:
abbr = spec.abbr,
disp = spec.disp,
extra = (getopt.usesCurrent and format ~= 'format_raw') and '<span class="currentage"></span>' or nil,
format = format or spec.format,
round = yes(args.round),
Line 726 ⟶ 753:
df = true,
mf = true,
template = true,
day = true,
day1 = true,
Anonymous user