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