Notice: Undefined offset: 828 in /home/maccabit/domains/maccabipedia.co.il/public_html/skins/Metrolook/customize/includes/app-header.php on line 59
יחידה:AgeBetween
מתוך מכביפדיה
גרסה מ־13:38, 24 באוקטובר 2025 מאת Kosh (שיחה | תרומות) (יצירת דף עם התוכן "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)...")
(הבדל) → הגרסה הקודמת | הגרסה האחרונה (הבדל) | הגרסה הבאה ← (הבדל)

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה: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