Модуль:Age: различия между версиями

Материал из Хоровая википедии
Перейти к навигации Перейти к поиску
Строка 4: Строка 4:
     currentYear = currentTime.year
     currentYear = currentTime.year
     if frame.args[4] then
     if frame.args[4] then
         currentYear = frame.arg[4]
         currentYear = tonumber(frame.arg[4])
     end
     end
     currentMonth = currentTime.month
     currentMonth = currentTime.month
     if frame.args[5] then
     if frame.args[5] then
         currentMonth = frame.args[5]
         currentMonth = tonumber(frame.args[5])
     end
     end
     currentDay = currentTime.day
     currentDay = currentTime.day
     if frame.args[6] then
     if frame.args[6] then
         currentDay = frame.args[6]
         currentDay = tonumber(frame.args[6])
     end
     end
     birthYear = frame.args[1]
     birthYear = tonumber(frame.args[1])
     birthMonth = 0
     birthMonth = 0
     if frame.args[2] then
     if frame.args[2] then
         birthMonth = frame.args[2]
         birthMonth = tonumber(frame.args[2])
     end
     end
     birthDay = 0
     birthDay = 0
     if frame.args[3] then
     if frame.args[3] then
         birthDay = frame.args[3]
         birthDay = tonumber(frame.args[3])
     end
     end
     age = currentYear - birthYear
     age = currentYear - birthYear

Версия от 12:40, 21 октября 2023

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

local utils = {}
function utils.getAge(frame)
    currentTime = os.date("*t")
    currentYear = currentTime.year
    if frame.args[4] then
        currentYear = tonumber(frame.arg[4])
    end
    currentMonth = currentTime.month
    if frame.args[5] then
        currentMonth = tonumber(frame.args[5])
    end
    currentDay = currentTime.day
    if frame.args[6] then
        currentDay = tonumber(frame.args[6])
    end
    birthYear = tonumber(frame.args[1])
    birthMonth = 0
    if frame.args[2] then
        birthMonth = tonumber(frame.args[2])
    end
    birthDay = 0
    if frame.args[3] 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