Module:Age/sandbox: Difference between revisions

Content deleted Content added
oops, need in use Module:Date/sandbox
add function call_generic to do the work for the age_xxx templates
Line 278:
end
 
-- LATER: If decide to use call_generic, probably do not need all the functions
local function age_days(frame)
-- which call it as a template such as {{age}} could invoke call_generic with
-- This implements {{age in days}}.
-- a parameter like "template=age_full_years".
local date1, date2 = get_dates(frame, false)
local function call_generic(frame, name)
-- Return the result required by the template identified by name.
local args = frame:getParent().args
local specs = {
age_days = {
show = 'd',
xdisp = 'disp_raw',
},
age_full_years = {
show = 'y',
xabbr = 'abbr_raw',
},
age_infant = {
-- Do not set show as special processing occurs later.
xabbr = yes(args.abbr) and 'abbr_on' or 'abbr_off',
xdisp = 'disp_age',
xsep = 'sep_space',
},
age_yd = {
show = 'yd',
xsep = args.sep ~= 'and' and 'sep_comma' or nil,
},
age_ym = {
show = 'ym',
xsep = 'sep_comma',
},
age_ymd = {
show = 'ymd',
want_mixture = true,
},
age_ymwd = {
show = 'ymwd',
},
}
local spec = specs[name]
local date1, date2 = get_dates(frame, spec.want_mixture)
if type(date1) == 'string' then
return date1
end
local args = frame:getParent().args
local parms = {
diff = date2 - date1,
xdisp = 'disp_raw',
show = 'd',
want_duration = yes(args.duration),
want_round = yes(args.round),
want_sc = yes(args.sc),
show = spec.show,
xabbr = spec.xabbr,
xdisp = spec.xdisp,
xsep = spec.xsep,
}
return age_generic(parms)
end
 
local function age_days(frame)
-- This implements {{age in days}}.
return call_generic(frame, 'age_days')
end
 
local function age_full_years(frame)
-- This implements {{age}}.
return call_generic(frame, 'age_full_years')
local date1, date2 = get_dates(frame, false)
if type(date1) == 'string' then
return date1
end
local args = frame:getParent().args
local parms = {
diff = date2 - date1,
show = 'y',
want_duration = yes(args.duration),
want_round = yes(args.round),
xabbr = 'abbr_raw',
}
return age_generic(parms)
end
 
local function age_infant(frame)
-- This implements {{age for infant}}.
localreturn date1, date2 = get_datescall_generic(frame, false'age_infant')
if type(date1) == 'string' then
return date1
end
local args = frame:getParent().args
local parms = {
diff = date2 - date1,
want_duration = yes(args.duration),
want_round = yes(args.round),
xabbr = yes(args.abbr) and 'abbr_on' or 'abbr_off',
xdisp = 'disp_age',
xsep = 'sep_space',
}
return age_generic(parms)
end
 
local function age_yd(frame)
-- This implements {{age in years and days}}.
localreturn date1, date2 = get_datescall_generic(frame, false'age_yd')
if type(date1) == 'string' then
return date1
end
local args = frame:getParent().args
local parms = {
diff = date2 - date1,
show = 'yd',
want_duration = yes(args.duration),
want_round = yes(args.round),
xsep = args.sep ~= 'and' and 'sep_comma' or nil,
}
return age_generic(parms)
end
 
local function age_ym(frame)
-- This implements {{age in years and months}}.
localreturn date1, date2 = get_datescall_generic(frame, false'age_ym')
if type(date1) == 'string' then
return date1
end
local args = frame:getParent().args
local parms = {
diff = date2 - date1,
xsep = 'sep_comma',
show = 'ym',
want_duration = yes(args.duration),
want_round = yes(args.round),
}
return age_generic(parms)
end
 
local function age_ymd(frame)
-- This implements {{age in years, months and days}}.
localreturn date1, date2 = get_datescall_generic(frame, true'age_ymd')
if type(date1) == 'string' then
return date1
end
local args = frame:getParent().args
local parms = {
diff = date2 - date1,
show = 'ymd',
want_duration = yes(args.duration),
want_round = yes(args.round),
want_sc = yes(args.sc),
}
return age_generic(parms)
end
 
local function age_ymwd(frame)
-- This implements {{age in years, months, weeks and days}}.
localreturn date1, date2 = get_datescall_generic(frame, false'age_ymwd')
if type(date1) == 'string' then
return date1
end
local args = frame:getParent().args
local parms = {
diff = date2 - date1,
show = 'ymwd',
want_duration = yes(args.duration),
want_round = yes(args.round),
want_sc = yes(args.sc),
}
return age_generic(parms)
end