More actions
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p.formatDate( | function p.formatDate(frame) | ||
local month = tonumber(frame.args[2]) or 1 | |||
local year = tonumber(frame.args[3]) or 1970 | |||
return mw.getContentLanguage():formatDate('F Y', string.format('%d-%d', year, month)) | return mw.getContentLanguage():formatDate('F Y', string.format('%d-%d', year, month)) | ||
end | end | ||
function p.calculateAge(birthMonth | function p.calculateAge(frame) | ||
local birthMonth = tonumber(frame.args[2]) or 1 | |||
local birthYear = tonumber(frame.args[3]) or 1970 | |||
local deathMonth = tonumber(frame.args[5]) or 1 | |||
local deathYear = tonumber(frame.args[6]) or 1970 | |||
local age = deathYear - birthYear | local age = deathYear - birthYear | ||
if deathMonth < birthMonth then | if deathMonth < birthMonth then | ||
age = age - 1 | age = age - 1 | ||
end | end | ||
return age | return age | ||
end | end | ||
function p.displayDateWithAge(frame) | function p.displayDateWithAge(frame) | ||
local date = p.formatDate(frame) | |||
local age = p.calculateAge(frame) | |||
local date = p.formatDate( | |||
local age = p.calculateAge( | |||
return string.format('%s (aged %d)', date, age) | return string.format('%s (aged %d)', date, age) | ||
end | end | ||
return p | return p |