Модуль:Age

Материал из Хоровая википедии
Перейти к навигации Перейти к поиску

Для документации этого модуля может быть создана страница Модуль:Age/doc

local utils = {}
function utils.getAge(frame)
    currentTime = os.date("*t")
    currentYear = currentTime.year
    if frame.args[4] and frame.args[4] ~= nil then
        currentYear = tonumber(frame.args[4])
    end
    currentMonth = currentTime.month
    if frame.args[5] and frame.args[5] ~= nil then
        currentMonth = tonumber(frame.args[5])
    end
    currentDay = currentTime.day
    if frame.args[6] and frame.args[6] ~= nil  then
        currentDay = tonumber(frame.args[6])
    end
    birthYear = tonumber(frame.args[1])
    birthMonth = 0
    if frame.args[2] and frame.args[2] ~= nil  then
        birthMonth = tonumber(frame.args[2])
    end
    birthDay = 0
    if frame.args[3] and frame.args[3] ~= nil   then
        birthDay = tonumber(frame.args[3])
    end
    age = currentYear - birthYear
    if birthMonth > 0 and currentMonth < birthMonth then
        age = age - 1
    else
        if birthDay > 0 and currentMonth == birthMonth and  currentDay < birthDay then
            age = age - 1
        end
    end
    return age
end


return utils