More actions
(Created page with "-- DeathMonthAgedMonthYear.lua local p = {} function p.formatDate(frame) local month = frame.args[1] or 1 local year = frame.args[2] or 1970 return mw.getContentLanguage():formatDate('F Y', string.format('%d-%d', year, month)) end function p.calculateAge(frame) local month = tonumber(frame.args[1]) or 1 local year = tonumber(frame.args[2]) or 1970 local currentMonth = tonumber(mw.getCurrentFrame():callParserFunction('#time', 'n')) local cu...") |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p.formatDate( | function p.formatDate(day, month, year) | ||
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( | function p.calculateAge(birthMonth, birthYear, deathMonth, deathYear) | ||
local age = deathYear - birthYear | |||
if deathMonth < birthMonth then | |||
local age = | |||
if | |||
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( | local birthMonth = tonumber(frame.args[1]) or 1 | ||
local age = p.calculateAge( | local birthYear = tonumber(frame.args[2]) or 2000 | ||
local deathMonth = tonumber(frame.args[3]) or 1 | |||
local deathYear = tonumber(frame.args[4]) or 2024 | |||
local date = p.formatDate(nil, deathMonth, deathYear) | |||
local age = p.calculateAge(birthMonth, birthYear, deathMonth, deathYear) | |||
return string.format('%s (aged %d)', date, age) | return string.format('%s (aged %d)', date, age) | ||
end | end | ||
return p | return p |
Latest revision as of 19:53, 7 June 2024
Documentation for this module may be created at Module:Deathagemonth/doc
local p = {} function p.formatDate(day, month, year) return mw.getContentLanguage():formatDate('F Y', string.format('%d-%d', year, month)) end function p.calculateAge(birthMonth, birthYear, deathMonth, deathYear) local age = deathYear - birthYear if deathMonth < birthMonth then age = age - 1 end return age end function p.displayDateWithAge(frame) local birthMonth = tonumber(frame.args[1]) or 1 local birthYear = tonumber(frame.args[2]) or 2000 local deathMonth = tonumber(frame.args[3]) or 1 local deathYear = tonumber(frame.args[4]) or 2024 local date = p.formatDate(nil, deathMonth, deathYear) local age = p.calculateAge(birthMonth, birthYear, deathMonth, deathYear) return string.format('%s (aged %d)', date, age) end return p