Notice: Undefined offset: 828 in /home/maccabit/domains/maccabipedia.co.il/public_html/skins/Metrolook/customize/includes/app-header.php on line 59
יחידה: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)...")
 
אין תקציר עריכה
שורה 1: שורה 1:
local p = {}
local p = {}


-- Calculates precise age between two dates (YYYY-MM-DD)
-- Calculates exact age between two dates (YYYY-MM-DD)
function p.ageBetween(frame)
function p.ageBetween(frame)
local dob = frame.args[1]
    local dob = frame.args[1]
local event = frame.args[2]
    local event = frame.args[2]
if not dob or not event then return "" end
    if not dob or not event then return "" end


local y1, m1, d1 = dob:match("(%d+)%-(%d+)%-(%d+)")
    local y1, m1, d1 = dob:match("(%d+)%-(%d+)%-(%d+)")
local y2, m2, d2 = event:match("(%d+)%-(%d+)%-(%d+)")
    local y2, m2, d2 = event:match("(%d+)%-(%d+)%-(%d+)")
if not (y1 and y2) then return "" end
    if not (y1 and y2) then return "" end


y1, m1, d1 = tonumber(y1), tonumber(m1), tonumber(d1)
    y1, m1, d1 = tonumber(y1), tonumber(m1), tonumber(d1)
y2, m2, d2 = tonumber(y2), tonumber(m2), tonumber(d2)
    y2, m2, d2 = tonumber(y2), tonumber(m2), tonumber(d2)


local years = y2 - y1
    local years = y2 - y1
local months = m2 - m1
    local months = m2 - m1
local days = d2 - d1
    local days = d2 - d1


if days < 0 then
    if days < 0 then
months = months - 1
        months = months - 1
local prevMonth = (m2 - 1) % 12
        -- get days in previous month
if prevMonth == 0 then prevMonth = 12 end
        local prevMonth = m2 - 1
local daysInPrevMonth = os.date("*t", os.time{year=y2, month=prevMonth+1, day=0}).day
        local prevYear = y2
days = days + daysInPrevMonth
        if prevMonth == 0 then prevMonth = 12; prevYear = y2 - 1 end
end
        local daysInPrevMonth = os.date("*t", os.time{year=prevYear, month=prevMonth+1, day=0}).day
        days = days + daysInPrevMonth
    end


if months < 0 then
    if months < 0 then
years = years - 1
        years = years - 1
months = months + 12
        months = months + 12
end
    end


return string.format("%d years, %d months, %d days", years, months, days)
    return string.format("%d years, %d months, %d days", years, months, days)
end
end


return p
return p

גרסה מ־13:52, 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 years, %d months, %d days", years, months, days)
end

return p