Content deleted Content added
implement Template:Death date and age |
enhance getDates to give better error messages if a required date is missing; allow dda to have unknown month/day per old template which allows unknown day |
||
Line 499:
-- Don't bother detecting if wantMixture is used because not needed and it is a poor option.
if not text then
if getopt.noMissing then
return nil -- this gives a nil date which gives an error
end
text = 'currentdate'
if getopt.flag == 'usesCurrent' then
Line 537 ⟶ 540:
end
local fix = getopt.fix and 'fix' or ''
local partialText = getopt.partial and 'partial' or ''
local dates = {}
Line 563 ⟶ 565:
if (getopt.partial and y and (m or not d)) or (y and m and d) then
dates[i] = Date(fix, partialText, y, m, d)
elseif not y and not m and not d
dates[i] = Date(flagCurrent())
end
end
end
else
getopt.textdates = true -- have parsed each date from a single text field
dates[1] = Date(fix, partialText, flagCurrent(fields[1]))
Line 576 ⟶ 578:
end
if not dates[1] then
return message(getopt.missing1 or 'Need valid year, month, day')
end
if getopt.single then
Line 582 ⟶ 584:
end
if not dates[2] then
return message(getopt.missing2 or 'Second date should be year, month, day')
end
return dates[1], dates[2]
Line 762 ⟶ 764:
-- Implement [[Template:Birth date and age]].
local args = frame:getParent().args
local options = {
noMissing = true,
single = true,
}
local date = getDates(frame, options)
if type(date) == 'string' then
Line 835 ⟶ 841:
-- Implement [[Template:Death date and age]].
local args = frame:getParent().args
local options = {
missing1 = 'Need valid death date (first date): year, month, day',
missing2 = 'Need valid birth date (second date): year, month, day',
noMissing = true,
partial = true,
}
local date1, date2 = getDates(frame, options)
if type(date1) == 'string' then
return date1
end
if diff.isnegative then
▲ return message('Need death date (first date) in full: year, month, day')
return message('Death date (first date) must occur after birth date (second date)')
end
local years
if diff.partial then
Line 851 ⟶ 862:
years = diff.years
end
if
return message('Invalid dates for calculating age')
end
local df = stripToNil(args.df) -- day first (dmy); default is month first (mdy)
local result
if date1.day then -- y, m, d known
'%-d %B %-Y' or▼
result = (df and
'%B %-d, %-Y'▼
▲ '%-d %B %-Y' or
result = result .. '<span style="display:none">(%-Y-%m-%d)</span>'▼
▲ '%B %-d, %-Y') ..
elseif date1.month then -- y, m known; d unknown
result =
'%B %-Y' ..
'<span style="display:none">(%-Y-%m-00)</span>'
else -- y known; m, d unknown
result =
'%-Y' ..
'<span style="display:none">(%-Y-00-00)</span>'
end
result = date1:text(result) ..
' (aged ' ..
|