יחידה:תאריך עברי

גרסה מ־17:57, 14 במאי 2015 מאת wikipedia:he>IKhitron (יצירת דף עם התוכן "function sub1(str, from, to) return mw.ustring.sub(str, from, to) end function find1(str, what, ...) local args = ...; local where = 1; if (args ~= nil) the...")
(הבדל) → הגרסה הקודמת | הגרסה האחרונה (הבדל) | הגרסה הבאה ← (הבדל)

function sub1(str, from, to)
	return mw.ustring.sub(str, from, to)
end

function find1(str, what, ...)
	local args = ...;
	local where = 1;
	if (args ~= nil) then
		where = args
	end
	local ans = mw.ustring.find(str, what, where, true);
	if (ans == nil) then
		ans = 0
	end
	return ans
end

function len1(s)
	if (s == nil) then
		return 0
	end
	return mw.ustring.len(s)
end

function takemonth(s)
	local ans
	if (s == "בתשרי") then
		ans = 7
	elseif (s == "בחשוון") then
		ans = 8
	elseif (s == "בכסלו") then
		ans = 9
	elseif (s == "בטבת") then
		ans = 10
	elseif (s == "בשבט") then
		ans = 11
	elseif (s == "באדר א'") then
		ans = 12
	elseif (s == "באדר ב'") then
		ans = 13
	elseif (s == "באדר") then
		ans = 13
	elseif (s == "בניסן") then
		ans = 1
	elseif (s == "באייר") then
		ans = 2
	elseif (s == "בסיוון") then
		ans = 3
	elseif (s == "בתמוז") then
		ans = 4
	elseif (s == "באב") then
		ans = 5
	elseif (s == "באלול") then
		ans = 6
	end
	return ans
end

function hebnum(s)
	local ans = 0
	local str = s
	while len1(str) > 0 do
		local next = sub1(str, 1, 1)
		if (next == "א") then
			ans = ans + 1
		elseif (next == "ב") then
			ans = ans + 2
		elseif (next == "ג") then
			ans = ans + 3
		elseif (next == "ד") then
			ans = ans + 4
		elseif (next == "ה") then
			ans = ans + 5
		elseif (next == "ו") then
			ans = ans + 6
		elseif (next == "ז") then
			ans = ans + 7
		elseif (next == "ח") then
			ans = ans + 8
		elseif (next == "ט") then
			ans = ans + 8
		elseif (next == "י") then
			ans = ans + 10
		elseif (next == "כ") then
			ans = ans + 20
		elseif (next == "ך") then
			ans = ans + 20
		elseif (next == "ל") then
			ans = ans + 30
		elseif (next == "מ") then
			ans = ans + 40
		elseif (next == "ם") then
			ans = ans + 40
		elseif (next == "נ") then
			ans = ans + 50
		elseif (next == "ן") then
			ans = ans + 50
		elseif (next == "ס") then
			ans = ans + 60
		elseif (next == "ע") then
			ans = ans + 70
		elseif (next == "פ") then
			ans = ans + 80
		elseif (next == "ף") then
			ans = ans + 80
		elseif (next == "צ") then
			ans = ans + 90
		elseif (next == "ץ") then
			ans = ans + 90
		elseif (next == "ק") then
			ans = ans + 100
		elseif (next == "ר") then
			ans = ans + 200
		elseif (next == "ש") then
			ans = ans + 300
		elseif (next == "ת") then
			ans = ans + 400
		end
		str = sub1(str, 2, len1(str))
	end
	return ans
end
function indent(m, d)
	local ans
	if (m == 7) then
		ans = 0
	elseif (m == 8) then
		ans = 30
	elseif (m == 9) then
		ans = 59
	elseif (m == 10) then
		ans = 88
	elseif (m == 11) then
		ans = 117
	elseif (m == 12) then
		ans = 147
	elseif (m == 13) then
		ans = 147
	elseif (m == 1) then
		ans = 176
	elseif (m == 2) then
		ans = 206
	elseif (m == 3) then
		ans = 235
	elseif (m == 4) then
		ans = 265
	elseif (m == 5) then
		ans = 294
	elseif (m == 6) then
		ans = 324
	end
	return ans + d - 1
end
function mindate(fix, frame)
	return to("28-08-" .. frame:callParserFunction("padleft", {hebnum(sub1(fix[3], 3, len1(fix[3]))) + 1000 *
		hebnum(sub1((fix[3]), 1, 2)) - 3761, 4}) .. " + " .. indent(takemonth(fix[2]), hebnum(fix[1])) .. " days", frame)
end
function exacttdate(hdate, mindate, frame)
	local count = 0
	while (count < 82) do
		if (from(mindate .. " + " .. count .. " days", frame) == hdate) then
			return to1(mindate .. " + " .. count .. " days", frame)
		end
		count = count + 1
	end
	return "error"
end
function from(gdate, frame)
	return frame:callParserFunction("#זמןמ:xhxjj xjx xhxjY", gdate)
end
function to(gdate, frame)
	return frame:callParserFunction("#זמןמ:j-m-Y", gdate)
end
function to1(gdate, frame)
	return frame:callParserFunction("#זמןמ:j בF Y", gdate)
end
function fixdate(hdate)
	local s1 = find1(hdate, " ");
	local s2 = find1(hdate, " ", s1 + 1);
	local s3 = find1(hdate, " ", s2 + 1);
	if (s3 > 0) then
		s2 = s3
	end
	h1 = sub1(hdate, 1, s1 - 1)
	h2 = sub1(hdate, s1 + 1, s2 - 1)
	h3 = sub1(hdate, s2 + 1, len1(hdate))
	if (len1(h3) > 1 and sub1(h3, 2, 2) ~= "'") then
		h3 = "ה'" .. h3
	end
	return {h1, h2, h3, h1 .. " " .. h2 .. " " .. h3}
end
function foo(frame)
	local hdate = frame.args[1]
	local fix = fixdate(hdate)
	return exacttdate(fix[4], mindate(fix, frame), frame)
end

return {
	['main'] = foo
}