Module:Age/sandbox: Difference between revisions

Content deleted Content added
validate parameters if warnings=1 in template; simplify message and generalize category; accept range=no with generic templates to help emulate inconsistent {{age in years nts}}
more camelCase
Line 1:
-- Implement various "age of" and other date-related templates.
 
local _Date, _current_date_currentDate
local function getExports(frame)
-- Return objects exported from the date module or its sandbox.
Line 8:
local datemod = require('Module:Date' .. sandbox)
_Date = datemod._Date
_current_date_currentDate = datemod._current
end
return _Date, _current_date_currentDate
end
 
Line 160:
ymw = { 'y', 'm', 'w', id = 'ymw' },
ymwd = { 'y', 'm', 'w', 'd', id = 'ymwd' },
yd = { 'y', 'd', id = 'yd', keepzerokeepZero = true },
m = { 'm', id = 'm' },
md = { 'm', 'd', id = 'md' },
Line 239:
-- v is a number (say 4 for 4 years), or a table ({4,5} for 4 or 5 years).
local islist = type(v) == 'table'
if (islist or v > 0) or (text.n == 0 and i == count) or (text.n > 0 and components.keepzerokeepZero) then
local fmt, vstr
if i == 1 and options.format == 'format_commas' then
Line 367:
defaultJoin = 'sep_space'
abbr = 'abbr_raw'
elseif parms.want_scwantSc then
defaultJoin = 'sep_serialcomma'
end
local diffOptions = {
round = parms.round,
duration = parms.want_durationwantDuration,
range = parms.range and true or nil,
}
local prefix
if parms.sortable then
local value = diff.age_days + (parms.want_durationwantDuration and 1 or 0) -- days and fraction of a day
if diff.isnegative then
value = -value
Line 407:
-- * text (a string error message)
-- A missing date is replaced with the current date.
-- If want_mixturewantMixture is true, a missing date component is replaced
-- from the current date, so can get a bizarre mixture of
-- specified/current y/m/d as has been done by some "age" templates.
Line 439:
end
end
local nodefaultnoDefault = imax == 0 and getopt.nomissingnoMissing
local dates = {}
if isNamed or imax >= 3 then
local nrDates = getopt.single and 1 or 2
if getopt.want_mixturewantMixture then
-- Cannot be partial since empty fields are set from current.
local components = { 'year', 'month', 'day' }
Line 459:
if (partial and y) or (y and m and d) then
dates[i] = Date(fix, partial, y, m, d)
elseif not y and not m and not d and not nodefaultnoDefault then
dates[i] = Date('currentdate')
end
end
end
elseif not nodefaultnoDefault then
getopt.textdates = true -- have parsed each date from a single text field
dates[1] = Date(fix, partial, fields[1] or 'currentdate')
Line 581:
age_ymwd = { -- {{age in years, months, weeks and days}}
show = 'ymwd',
want_mixturewantMixture = true,
},
}
Line 612:
range = range,
partial = spec.partial or spec.range,
want_mixturewantMixture = spec.want_mixturewantMixture,
}
local date1, date2 = getDates(frame, getopt)
Line 626:
local parms = {
diff = date2 - date1,
want_durationwantDuration = spec.duration or yes(args.duration),
range = range,
want_scwantSc = yes(args.sc),
show = args.show == 'hide' and 'hide' or spec.show,
abbr = spec.abbr,
Line 646:
-- Implement [[Template:Birth date and age]].
local args = frame:getParent().args
local options = { nomissingnoMissing=true, single=true }
local date = getDates(frame, options)
if type(date) == 'string' then
Line 722:
-- The returned value is negative for dates before 1 January 1 AD
-- despite the fact that GSD is not defined for such dates.
local date = getDates(frame, { want_mixturewantMixture=true, single=true })
if type(date) == 'string' then
return date
Line 763:
local args = frame:getParent().args
local parms = {
want_durationwantDuration = yes(args.duration),
range = yes(args.range) or (args.range == 'dash' and 'dash' or nil),
want_scwantSc = yes(args.sc),
}
local fix = yes(args.fix) and 'fix' or ''