Модуль:Age: различия между версиями
Перейти к навигации
Перейти к поиску
Palkiviad (обсуждение | вклад) |
Palkiviad (обсуждение | вклад) |
||
Строка 3: | Строка 3: | ||
currentTime = os.date("*t") | currentTime = os.date("*t") | ||
currentYear = currentTime.year | currentYear = currentTime.year | ||
if frame.args[4] then | if frame.args[4] and frame.args[4] ~= nil then | ||
currentYear = tonumber(frame.args[4]) | currentYear = tonumber(frame.args[4]) | ||
end | end | ||
currentMonth = currentTime.month | currentMonth = currentTime.month | ||
if frame.args[5] then | if frame.args[5] and frame.args[5] ~= nil then | ||
currentMonth = tonumber(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] and frame.args[6] ~= nil then | ||
currentDay = tonumber(frame.args[6]) | currentDay = tonumber(frame.args[6]) | ||
end | end | ||
birthYear = tonumber(frame.args[1]) | birthYear = tonumber(frame.args[1]) | ||
birthMonth = 0 | birthMonth = 0 | ||
if frame.args[2] then | if frame.args[2] and frame.args[2] ~= nil then | ||
birthMonth = tonumber(frame.args[2]) | birthMonth = tonumber(frame.args[2]) | ||
end | end | ||
birthDay = 0 | birthDay = 0 | ||
if frame.args[3] then | if frame.args[3] and frame.args[3] ~= nil then | ||
birthDay = tonumber(frame.args[3]) | birthDay = tonumber(frame.args[3]) | ||
end | end | ||
Строка 33: | Строка 33: | ||
return age | return age | ||
end | end | ||
return utils | return utils |
Версия от 12:53, 21 октября 2023
Для документации этого модуля может быть создана страница Модуль: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