More actions
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 2: | Line 2: | ||
function p.formatDate(frame) | function p.formatDate(frame) | ||
local day = frame.args[ | local day = tonumber(frame.args[4]) or 1 | ||
local month = frame.args[ | local month = tonumber(frame.args[5]) or 1 | ||
local year = frame.args[ | local year = tonumber(frame.args[6]) or 1970 | ||
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 |
Latest revision as of 19:43, 7 June 2024
Documentation for this module may be created at Module:Deathage/doc
local p = {} function p.formatDate(frame) local day = tonumber(frame.args[4]) or 1 local month = tonumber(frame.args[5]) or 1 local year = tonumber(frame.args[6]) or 1970 return mw.getContentLanguage():formatDate('j F Y', string.format('%d-%d-%d', year, month, day)) end function p.calculateAge(frame) local birthDay = tonumber(frame.args[1]) or 1 local birthMonth = tonumber(frame.args[2]) or 1 local birthYear = tonumber(frame.args[3]) or 1970 local deathDay = tonumber(frame.args[4]) or 1 local deathMonth = tonumber(frame.args[5]) or 1 local deathYear = tonumber(frame.args[6]) or 1970 local age = deathYear - birthYear if (deathMonth < birthMonth) or (deathMonth == birthMonth and deathDay < birthDay) then age = age - 1 end return age end function p.displayDateWithAge(frame) local date = p.formatDate(frame) local age = p.calculateAge(frame) return string.format('%s (aged %d)', date, age) end return p