ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:AgeBetween/תיעוד
local p = {}
-- Calculates precise age between two dates (YYYY-MM-DD)
function p.ageBetween(frame)
local dob = frame.args[1]
local event = frame.args[2]
if not dob or not event then return "" end
local y1, m1, d1 = dob:match("(%d+)%-(%d+)%-(%d+)")
local y2, m2, d2 = event:match("(%d+)%-(%d+)%-(%d+)")
if not (y1 and y2) then return "" end
y1, m1, d1 = tonumber(y1), tonumber(m1), tonumber(d1)
y2, m2, d2 = tonumber(y2), tonumber(m2), tonumber(d2)
local years = y2 - y1
local months = m2 - m1
local days = d2 - d1
if days < 0 then
months = months - 1
local prevMonth = (m2 - 1) % 12
if prevMonth == 0 then prevMonth = 12 end
local daysInPrevMonth = os.date("*t", os.time{year=y2, month=prevMonth+1, day=0}).day
days = days + daysInPrevMonth
end
if months < 0 then
years = years - 1
months = months + 12
end
return string.format("%d years, %d months, %d days", years, months, days)
end
return p