More actions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p.formatDate(frame) | function p.formatDate(frame) | ||
local day = frame.args[1] or 1 | local day = frame.args[1] or 1 | ||
Line 6: | Line 7: | ||
return mw.getContentLanguage():formatDate('j F Y', string.format('%d-%d-%d', year, month, day)) | return mw.getContentLanguage():formatDate('j F Y', string.format('%d-%d-%d', year, month, day)) | ||
end | end | ||
function p.calculateAge(frame) | function p.calculateAge(frame) | ||
local | local birthDay = tonumber(frame.args[1]) or 1 | ||
local | local birthMonth = tonumber(frame.args[2]) or 1 | ||
local | local birthYear = tonumber(frame.args[3]) or 1970 | ||
local | local deathDay = tonumber(frame.args[4]) or 1 | ||
local | local deathMonth = tonumber(frame.args[5]) or 1 | ||
local | local deathYear = tonumber(frame.args[6]) or 1970 | ||
local age = | |||
if ( | local age = deathYear - birthYear | ||
if (deathMonth < birthMonth) or (deathMonth == birthMonth and deathDay < birthDay) 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 date = p.formatDate(frame) | ||
Line 24: | Line 29: | ||
return string.format('%s (aged %d)', date, age) | return string.format('%s (aged %d)', date, age) | ||
end | end | ||
return p | return p |