(יצירת דף עם התוכן "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)...") |
אין תקציר עריכה |
||
| (גרסת ביניים אחת של אותו משתמש אינה מוצגת) | |||
| שורה 1: | שורה 1: | ||
local p = {} | local p = {} | ||
-- Calculates | -- Calculates exact age between two dates (YYYY-MM-DD) | ||
function p.ageBetween(frame) | 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 | |||
-- get days in previous month | |||
local prevMonth = m2 - 1 | |||
local prevYear = y2 | |||
if prevMonth == 0 then prevMonth = 12; prevYear = y2 - 1 end | |||
local daysInPrevMonth = os.date("*t", os.time{year=prevYear, 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 שנים, %d חודשים, %d ימים", years, months, days) | |||
end | end | ||
return p | return p | ||
גרסה אחרונה מ־14:10, 24 באוקטובר 2025
ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:AgeBetween/תיעוד
local p = {}
-- Calculates exact 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
-- get days in previous month
local prevMonth = m2 - 1
local prevYear = y2
if prevMonth == 0 then prevMonth = 12; prevYear = y2 - 1 end
local daysInPrevMonth = os.date("*t", os.time{year=prevYear, 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 שנים, %d חודשים, %d ימים", years, months, days)
end
return p