Module:AgeCalculator

From Cyraxx Wiki - lolcow.city
Jump to navigation Jump to search

Documentation for this module may be created at Module:AgeCalculator/doc

local p = {}

function p.age(frame)
    local year = tonumber(frame.args.year)
    local month = tonumber(frame.args.month)
    local day = tonumber(frame.args.day)

    if not year or not month or not day then
        return "Invalid date"
    end

    local today = os.date("*t")
    local age = today.year - year

    if today.month < month or (today.month == month and today.day < day) then
        age = age - 1
    end

    return age
end

return p