יחידה:תאריך עברי: הבדלים בין גרסאות בדף

אין תקציר עריכה
מ 197 גרסאות של הדף wikipedia:he:יחידה:תאריך_עברי יובאו
 
(41 גרסאות ביניים של 5 משתמשים אינן מוצגות)
שורה 9: שורה 9:
}
}


typomonthtable = {["חשון"] = "חשוון", ["כסליו"] = "כסלו", ["אדר א"] = "אדר א'",
typomonthtable = {["חשון"] = "חשוון", ["כסליו"] = "כסלו",
["אדר ב"] = "אדר ב'", ["חשון"] = "חשוון", ["סיון"] = "סיוון",
["חשון"] = "חשוון", ["סיון"] = "סיוון",
["מרחשון"] = "חשוון", ["מרחשוון"] = "חשוון", ["מר-חשוון"] = "חשוון",
["מרחשון"] = "חשוון", ["מרחשוון"] = "חשוון", ["מר-חשוון"] = "חשוון",
["מנחם אב"] = "אב", ["מנחם-אב"] = "אב",
["מנחם אב"] = "אב", ["מנחם-אב"] = "אב",
["שבט (חודש)|שבט"] = "שבט", ["שבט (חודש)"] = "שבט"}
["שבט (חודש)|שבט"] = "שבט", ["שבט (חודש)"] = "שבט"
}


lastletters = {["כ"] = "ך", ["מ"] = "ם", ["נ"] = "ן", ["פ"] = "ף", ["צ"] = "ץ"}
lastletters = {["כ"] = "ך", ["מ"] = "ם", ["נ"] = "ן", ["פ"] = "ף", ["צ"] = "ץ"}
שורה 22: שורה 23:


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


שורה 53: שורה 51:
function mindate(fix)
function mindate(fix)
local indenttable = {176, 206, 235, 265, 294, 324, 0, 30, 59, 88, 117, 147, 147}
local indenttable = {176, 206, 235, 265, 294, 324, 0, 30, 59, 88, 117, 147, 147}
return same("28-08-" .. frame:callParserFunction("padleft", {hebnum(sub1(fix[3], 3, len1(fix[3]))) + 1000
return same("28-08-" .. takeyear(fix[3]) .. " + " .. (indenttable[monthtable[sub1(fix[2], 2)]]
* hebnum(sub1((fix[3]), 1, 2)) - 3761, 4}) .. " + " .. (indenttable[monthtable[sub1(fix[2], 2)]]
+ hebnum(fix[1]) - 1) .. " days")
+ hebnum(fix[1]) - 1) .. " days")
end
function takeyear(year)
local new
if 0 < find1(year, "אלפים")
then new = hebnum(sub1(year, 1, 2)) * 1000
else new = hebnum(sub1(year, 3, len1(year))) + 1000
* hebnum(sub1((year), 1, 2)) end
return frame:callParserFunction("padleft", {new - 3761, 4})
end
end


שורה 70: שורה 76:
greg = same(greg .. " - ".. diffs .. "days")
greg = same(greg .. " - ".. diffs .. "days")
checkcasp(greg)
checkcasp(greg)
if makeformat then
return frame:callParserFunction("#זמןמ:" .. makeformat, greg)
end
return format(greg) end
return format(greg) end
count = count + 1
count = count + 1
שורה 81: שורה 90:
checkcasp("01-01-" .. wyear)
checkcasp("01-01-" .. wyear)
return wyear .. "-" .. frame:callParserFunction("padleft", {wyear + 1, 4})
return wyear .. "-" .. frame:callParserFunction("padleft", {wyear + 1, 4})
end
function opposite(gdate, format)
if samesame == true
then samesame = false
return format(gdate) end
end
end


function from(gdate)
function from(gdate)
local ans = opposite(gdate, to)
if ans ~= nil
then return ans end
if frame.args["links"] == "yes"
if frame.args["links"] == "yes"
then return "[[" .. frame:callParserFunction("#זמןמ:xhxjj xjx", gdate) .. "]] [["
then return "[[" .. frame:callParserFunction("#זמןמ:xhxjj xjx", gdate) .. "]] [["
שורה 91: שורה 109:


function frommonth(gdate)
function frommonth(gdate)
local ans = opposite(gdate, tomonth)
if ans ~= nil
then return ans end
if frame.args["links"] == "yes"
if frame.args["links"] == "yes"
then return "[[" .. frame:callParserFunction("#זמןמ:xjF", gdate) .. "]] [["
then return "[[" .. frame:callParserFunction("#זמןמ:xjF", gdate) .. "]] [["
שורה 98: שורה 119:


function fromonlymonth(gdate)
function fromonlymonth(gdate)
local ans = opposite(gdate, toonlymonth)
if ans ~= nil
then return ans end
if frame.args["links"] == "yes"
if frame.args["links"] == "yes"
then return "[[" .. frame:callParserFunction("#זמןמ:xjF", gdate) .. "]]" end
then return "[[" .. frame:callParserFunction("#זמןמ:xjF", gdate) .. "]]" end
שורה 104: שורה 128:


function fromyear(gdate)
function fromyear(gdate)
local ans = opposite(gdate, toyear)
if ans ~= nil
then return ans end
if frame.args["links"] == "yes"
if frame.args["links"] == "yes"
then return "[[" .. frame:callParserFunction("#זמןמ:xhxjY", gdate) .. "]]" end
then return "[[" .. frame:callParserFunction("#זמןמ:xhxjY", gdate) .. "]]" end
שורה 111: שורה 138:
function same(gdate)
function same(gdate)
return frame:callParserFunction("#זמןמ:d-m-Y", gdate)
return frame:callParserFunction("#זמןמ:d-m-Y", gdate)
end
function makeyear(gdate)
local year = frame:callParserFunction("#זמןמ:Y", gdate)
if tonumber(year) < 1000 and which
then year = sub1(year, 2)
end
return year
end
end


function to(gdate)
function to(gdate)
local year = makeyear(gdate)
if frame.args["links"] == "yes"
if frame.args["links"] == "yes"
then return "[[" .. frame:callParserFunction("#זמןמ:j בF", gdate) .. "]] [["
then return "[[" .. frame:callParserFunction("#זמןמ:j בF", gdate) .. "]] [["
.. frame:callParserFunction("#זמןמ:Y", gdate) .. "]]" end
.. year .. "]]" end
return frame:callParserFunction("#זמןמ:j בF Y", gdate)
return frame:callParserFunction("#זמןמ:j בF", gdate) .. " " .. year
end
end


function tomonth(gdate)
function tomonth(gdate)
local year = makeyear(gdate)
if frame.args["links"] == "yes"
if frame.args["links"] == "yes"
then return "[[" .. frame:callParserFunction("#זמןמ:F", gdate) .. "]] [["
then return "[[" .. frame:callParserFunction("#זמןמ:F", gdate) .. "]] [["
.. frame:callParserFunction("#זמןמ:Y", gdate) .. "]]" end
.. year .. "]]" end
return frame:callParserFunction("#זמןמ:F Y", gdate)
return frame:callParserFunction("#זמןמ:F", gdate) .. " " .. year
end
end


שורה 134: שורה 171:


function toyear(gdate)
function toyear(gdate)
local year = makeyear(gdate)
if frame.args["links"] == "yes"
if frame.args["links"] == "yes"
then return "[[" .. frame:callParserFunction("#זמןמ:Y", gdate) .. "]]" end
then return "[[" .. year .. "]]" end
return frame:callParserFunction("#זמןמ:Y", gdate)
return year
end
 
function fixmonth(hdate)
local point
local max = 0
local place = 0
for m, mm in pairs(typomonthtable) do
point = find1(hdate, m)
if point > 0 and max < len1(m)
then max = len1(m)
place = m end
end
if max > 0
then point = find1(hdate, place)
return sub1(hdate, 1, point - 1) .. typomonthtable[place] .. sub1(hdate, point + len1(place)) end
return hdate
end
end


function fixdate(hdate)
function fixdate(hdate1)
local hdate = fixmonth(hdate1)
if 1 == find1(hdate, "ראש חודש")
if 1 == find1(hdate, "ראש חודש")
then hdate = "א' ב" .. sub1(hdate, 10) end
then hdate = "א' ב" .. sub1(hdate, 10) end
local h1, h2, h3 = parts(hdate)
--[=[
local s1 = find1(hdate, " ")
local s1 = find1(hdate, " ")
local s2 = find1(hdate, " ", s1 + 1)
local s2 = find1(hdate, " ", s1 + 1)
שורה 150: שורה 207:
h2 = sub1(hdate, s1 + 1, s2 - 1)
h2 = sub1(hdate, s1 + 1, s2 - 1)
h3 = sub1(hdate, s2 + 1, len1(hdate))
h3 = sub1(hdate, s2 + 1, len1(hdate))
]=]
if (len1(h3) > 1 and sub1(h3, 2, 2) ~= "'") then
if (len1(h3) > 1 and sub1(h3, 2, 2) ~= "'") then
h3 = "ה'" .. h3 end
h3 = "ה'" .. h3 end
--[=[
for m, mm in pairs(typomonthtable) do
for m, mm in pairs(typomonthtable) do
if h2 == "ב" .. m
if h2 == "ב" .. m
then h2 = "ב" .. mm end
then h2 = "ב" .. mm end
end
end
]=]
for y, yy in pairs(lastletters) do
for y, yy in pairs(lastletters) do
if sub1(h3, len1(h3)) == y
if sub1(h3, len1(h3)) == y
שורה 261: שורה 321:


function fromhebrew1(hdate)
function fromhebrew1(hdate)
local ht, rem = findhdatetype(hdate)
local ht, rem = findhdatetype(fixmonth(hdate))
if ht == "dmy"
if ht == "dmy"
then return ifwhich(fromhebrewdate(rem, to))
then return ifwhich(fromhebrewdate(rem, to))
שורה 273: שורה 333:
function findhdatetype(hdate)
function findhdatetype(hdate)
local rem = mw.text.trim(remove(hdate))
local rem = mw.text.trim(remove(hdate))
local day, month, year = parts(hdate)
if day ~= nil
then return "dmy", rem end
if month ~= nil
then return "my", rem end
return "y", rem
--[=[
for m, mm in pairs(monthtable) do
for m, mm in pairs(monthtable) do
if find1(rem, m) == 1 then
if find1(rem, m) == 1 then
שורה 280: שורה 347:
return "y", rem end
return "y", rem end
return "dmy", rem
return "dmy", rem
]=]
end
end


function fromhebrew(f)
function fromhebrew(f)
if noth(f.args[1]) then return "" end
which = true
which = true
return fromhebrewandverify(f)
end
function fromhebrewformat(f)
which = true
makeformat = f.args["format"]
return fromhebrewandverify(f)
return fromhebrewandverify(f)
end
end
שורה 290: שורה 363:
function verify(f)
function verify(f)
frame = f
frame = f
if noth(frame.args[1]) then return "" end
which = false
which = false
local success, res = pcall(pick1, frame.args[1], frame.args[2], "[[קטגוריה:חוסר מתאם בין תאריך עברי לתאריך לועזי]]")
local success, res = pcall(pick1, frame.args[1], frame.args[2], "[[קטגוריה:חוסר מתאם בין תאריך עברי לתאריך לועזי]]")
שורה 349: שורה 421:
then rem = sub1(rem, 1, s2) .. "0" .. sub1(rem, s2 + 1) end
then rem = sub1(rem, 1, s2) .. "0" .. sub1(rem, s2 + 1) end
local take = takenumbers(rem)
local take = takenumbers(rem)
if to(take) ~= rem
if remove(to(take)) ~= rem
then error("wrong date", 0) end
then error("wrong date", 0) end
checkcasp(take)
checkcasp(take)
שורה 423: שורה 495:
-- .. frame.args["type"] .. " לועזי מדויק]]" end
-- .. frame.args["type"] .. " לועזי מדויק]]" end
return "" end
return "" end
if hsuccess and wsuccess
if wsuccess and hsuccess
then if ht == "dmy" then return hdw
then if wt == "dmy" then return wdate
elseif wt == "dmy" then return wdate
elseif ht == "dmy" then return hdw
elseif wt == "my" then return wdate
elseif ht == "my" then return hdw
elseif ht == "my" then return hdw
elseif wt == "my" then return wdate
elseif wt == "y" then return wdate
elseif ht == "y" then return hdw
else return hdw end
else return wdate end
elseif wsuccess then return wdate
elseif hsuccess then return hdw
elseif hsuccess then return hdw
elseif wsuccess then return wdate
elseif wt == "about" then return wdate
elseif ht == "about" then return hdate
else return hdate end
else return wdate end
end
end


שורה 444: שורה 516:
function pick(f)
function pick(f)
frame = f
frame = f
if noth(frame.args["hebrew"]) then return "" end
local hebrew = frame.args["hebrew"]
local success, res = pcall(pick1, frame.args["hebrew"], frame.args["world"])
local world = frame.args["world"]
local habout = false
local wabout = false
if frame:expandTemplate({title = "גיל לערכי אישים/מקורב", args = {str = hebrew}}) ~= ""
then hebrew = ""
habout = true end
if frame:expandTemplate({title = "גיל לערכי אישים/מקורב", args = {str = world}}) ~= ""
then world = ""
wabout = true end
local success, res = pcall(pick1, hebrew, world)
if success
if success
then return res
then if habout and world == ""
then return frame.args["hebrew"] end
if wabout and hebrew == ""
then return frame.args["world"] end
return res
elseif frame.args["error"] == nil
elseif frame.args["error"] == nil
then return aserror(res) end
then return aserror(res) end
שורה 468: שורה 553:
frame = f
frame = f
which = true
which = true
return tohebrew0(frame.args[1])
end
function samedate(f)
frame = f
which = true
samesame = true
return tohebrew0(frame.args[1])
return tohebrew0(frame.args[1])
end
end
שורה 479: שורה 571:
end
end


function noth(hdate)
function parts(hdate)
return 0 < find1(hdate, "אלפים")
local funcs = {
{function() return w[1] end},
{function() return w[2], w[1] end,
function() return c(w[2], w[1]) end},
{function() return w[3], w[2], w[1] end,
function() return c(w[3], w[2]), w[1] end,
function() return w[3], c(w[2], w[1]) end},
{function() return w[4], c(w[3], w[2]), w[1] end,
function() return c(w[4], w[3]), w[2], w[1] end,
nil,
function() return c(w[4], w[3]), c(w[2], w[1]) end},
{nil,
function() return c(w[5], w[4]), c(w[3], w[2]), w[1] end}}
function c(x, y) return y .. " " .. x end
w = takewords(hdate)
local code = 1
if 0 < find1(hdate, "אלפים")
then code = code + 1 end
if 1 == find1(hdate, "אדר א")
then code = code + 2 end
if 1 == find1(hdate, "אדר ב")
then code = code + 2 end
local year, month, day = funcs[#w][code]()
return day, month, year
end
 
function takewords(str)
local count = 1
local ans = {}
local cur = str
while find1(cur, " ") > 0 do
ans[count] = sub1(cur, 1, find1(cur, " ") - 1)
count = count + 1
cur = sub1(cur, find1(cur, " ") + 1)
end
ans[count] = cur
return ans
end
end


return {fromhebrew = fromhebrew, tohebrew = tohebrew, verify = verify, pick = pick}
return {fromhebrew = fromhebrew, tohebrew = tohebrew, verify = verify, pick = pick, samedate = samedate,
fromhebrewformat = fromhebrewformat}