Content deleted Content added
copy from Module:Age and tweak comment |
implement Template:Birth date and age (draft, to be tested) |
||
Line 608:
end
return date_difference(parms)
end
local function bda(frame)
-- Implement [[Template:Birth date and age]].
local args = frame:getParent().args
local date = get_dates(frame, { single=true })
if type(date) == 'string' then
return date -- error text
end
local Date = get_exports(frame)
local now = Date('currentdate')
local diff = now - date
if diff.isnegative or diff.years > 150 then
return message('Invalid birth date for calculating age')
end
local disp, show = 'disp_raw', 'y'
if diff.years < 3 then
disp = 'disp_age'
if diff.years >= 1 then
show = 'ym'
else
show = 'md'
end
end
local df = strip_to_nil(args.df) -- day first (dmy); default is month first (mdy)
local result = df and
'(<span class="bday">%-Y-%m-%d</span>) </span>%-d %B %-Y' or
'(<span class="bday">%-Y-%m-%d</span>) </span>%B %-d, %-Y'
result = '<span style="display:none"> ' ..
date:text(result) ..
'<span class="noprint ForceAgeToShow"> ' ..
'(age ' ..
date_difference({
diff = diff,
show = show,
abbr = 'abbr_off',
disp = disp,
sep = 'sep_space',
}) ..
')</span>'
return result
end
Line 699 ⟶ 740:
return {
age_generic = age_generic, -- can emulate several age templates
birth_date_and_age = bda, -- Template:Birth_date_and_age
gsd = date_to_gsd, -- Template:Gregorian_serial_date
extract = date_extract, -- Template:Extract
|