Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Deathagemonth

From Catpedia

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