Content deleted Content added
implement Template:Birth date and age (draft, to be tested) |
new collection; try different birth date and age procedures: reject empty birth date; show age in days if months < 1, or months if years < 2, otherwise years |
||
Line 13:
end
local function collection()▼
Collection = {
▲ -- Return a table to hold items.
▲ add = function (self, item)
self.n = self.n + 1
self[self.n] = item
end
join = function (self, sep)▼
return table.concat(self, sep)
▲ end,
end,▼
}▼
▲end
if self.n > 0 and (pos == nil or (0 < pos and pos <= self.n)) then
self.n = self.n - 1
return table.remove(self, pos)
end
end,
sort = function (self, comp)
table.sort(self, comp)
end,
return setmetatable({n = 0}, Collection)
end
Collection.__index = Collection
local function strip_to_nil(text)
Line 66 ⟶ 78:
local numstr = tostring(number)
local length = #numstr
local places =
local pos = 0
repeat
Line 73 ⟶ 85:
until pos >= length
places:add(length)
local groups =
for i = places.n, 2, -1 do
local p1 = length - places[i] + 1
Line 214 ⟶ 226:
local function make_text(values, components, names, options)
-- Return wikitext representing an age or duration.
local text =
local count = #values
local sep = names.sep or ''
Line 420 ⟶ 432:
end
end
local
local dates = {}
if is_named or imax >=
local nr_dates = getopt.single and 1 or 2
if getopt.want_mixture then
-- Cannot be partial since empty fields are set from current.
Line 440 ⟶ 452:
if (partial and y) or (y and m and d) then
dates[i] = Date(fix, partial, y, m, d)
elseif not
dates[i] = Date('currentdate')
end
end
end
elseif not nodefault then
getopt.textdates = true -- have parsed each date from a single text field
dates[1] = Date(fix, partial, fields[1] or 'currentdate')
if not getopt.single then
dates[2] = Date(fix, partial, fields[2] or 'currentdate')
end
Line 455 ⟶ 467:
return message('Need valid year, month, day')
end
if getopt.single then
return dates[1]
end
Line 613 ⟶ 625:
-- Implement [[Template:Birth date and age]].
local args = frame:getParent().args
local date = get_dates(frame, { nomissing=true, single=true })
if type(date) == 'string' then
return date -- error text
Line 624 ⟶ 636:
end
local disp, show = 'disp_raw', 'y'
if diff.years <
disp = 'disp_age'
if diff.years
show = '
else
show = '
end
end
|