יחידה:תאריך עברי – הבדלי גרסאות

מ. רובין (שיחה | תרומות)
אין תקציר עריכה
מ. רובין (שיחה | תרומות)
ביטול גרסה 804939 של מ. רובין (שיחה)
שורה 1: שורה 1:
mtable = { "ינואר", "פברואר", "מרץ", "אפריל", "מאי", "יוני",
mtable = {"ינואר", "פברואר", "מרץ", "אפריל", "מאי", "יוני",
"יולי", "אוגוסט", "ספטמבר", "אוקטובר", "נובמבר", "דצמבר", }
"יולי", "אוגוסט", "ספטמבר", "אוקטובר", "נובמבר", "דצמבר", }


monthtable = {
monthtable = {
["תשרי"] = 7,
["תשרי"] = 7, ["חשוון"] = 8, ["כסלו"] = 9, ["טבת"] = 10,
["חשוון"] = 8,
["שבט"] = 11, ["אדר א'"] = 12, ["אדר ב'"] = 13, ["אדר"] = 13,
["כסלו"] = 9,
["ניסן"] = 1, ["אייר"] = 2, ["סיוון"] = 3, ["תמוז"] = 4,
["טבת"] = 10,
["אב"] = 5, ["אלול"] = 6,
["שבט"] = 11,
}
["אדר א'"] = 12,
["אדר ב'"] = 13,
["אדר"] = 13,
["ניסן"] = 1,
["אייר"] = 2,
["סיוון"] = 3,
["תמוז"] = 4,
["אב"] = 5,
["אלול"] = 6,
}


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


local langObject = mw.getContentLanguage()
lastletters = {["כ"] = "ך", ["מ"] = "ם", ["נ"] = "ן", ["פ"] = "ף", ["צ"] = "ץ"}


function sub1(str, from, to)
function sub1(str, from, to)
שורה 46: שורה 28:
function len1(s)
function len1(s)
if (s == nil) then
if (s == nil) then
return 0
return 0 end
end
return mw.ustring.len(s)
return mw.ustring.len(s)
end
end
שורה 53: שורה 34:
function hebnum(s)
function hebnum(s)
numberstable = {
numberstable = {
["א"] = 1,
["א"] = 1, ["ב"] = 2, ["ג"] = 3, ["ד"] = 4, ["ה"] = 5,
["ב"] = 2,
["ו"] = 6, ["ז"] = 7, ["ח"] = 8, ["ט"] = 9, ["י"] = 10,  
["ג"] = 3,
["כ"] = 20, ["ך"] = 20, ["ל"] = 30, ["מ"] = 40, ["ם"] = 40,  
["ד"] = 4,
["נ"] = 50, ["ן"] = 50, ["ס"] = 60, ["ע"] = 70, ["פ"] = 80,  
["ה"] = 5,
["ף"] = 80, ["צ"] = 90, ["ץ"] = 90, ["ק"] = 100, ["ר"] = 200,  
["ו"] = 6,
["ש"] = 300, ["ת"] = 400, ["'"] = 0, ["\""] = 0,}
["ז"] = 7,
["ח"] = 8,
["ט"] = 9,
["י"] = 10,
["כ"] = 20,
["ך"] = 20,
["ל"] = 30,
["מ"] = 40,
["ם"] = 40,
["נ"] = 50,
["ן"] = 50,
["ס"] = 60,
["ע"] = 70,
["פ"] = 80,
["ף"] = 80,
["צ"] = 90,
["ץ"] = 90,
["ק"] = 100,
["ר"] = 200,
["ש"] = 300,
["ת"] = 400,
["'"] = 0,
["\""] = 0,
}
local ans = 0
local ans = 0
local str = s
local str = s
שורה 93: שורה 50:


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-" .. takeyear(fix[3]) .. " + " .. (indenttable[monthtable[sub1(fix[2], 2)]]
return same("28-08-" .. takeyear(fix[3]) .. " + " .. (indenttable[monthtable[sub1(fix[2], 2)]]
+ hebnum(fix[1]) - 1) .. " days")
+ hebnum(fix[1]) - 1) .. " days")
שורה 100: שורה 57:
function takeyear(year)
function takeyear(year)
local new
local new
if 0 < find1(year, "אלפים") then
if 0 < find1(year, "אלפים")
new = hebnum(sub1(year, 1, 2)) * 1000
then new = hebnum(sub1(year, 1, 2)) * 1000
else
else new = hebnum(sub1(year, 3, len1(year))) + 1000
new = hebnum(sub1(year, 3, len1(year))) + 1000
* hebnum(sub1((year), 1, 2)) end
* hebnum(sub1((year), 1, 2))
return frame:callParserFunction("padleft", {new - 3761, 4})
end
return frame:callParserFunction("padleft", { new - 3761, 4 })
end
end


שורה 119: שורה 74:
local diffs = diff(greg)
local diffs = diff(greg)
if diffs < 0 then diffs = 0 end
if diffs < 0 then diffs = 0 end
greg = same(greg .. " - " .. diffs .. "days")
greg = same(greg .. " - ".. diffs .. "days")
checkcasp(greg)
checkcasp(greg)
if makeformat then
if makeformat then
return langObject:formatDate(makeformat, greg)
return frame:callParserFunction("#זמןמ:" .. makeformat, greg)
end
end
return format(greg)
return format(greg) end
end
count = count + 1
count = count + 1
end
end
שורה 132: שורה 86:


function exacttdate1(hyear)
function exacttdate1(hyear)
local wyear = frame:callParserFunction("padleft", { hebnum(sub1(hyear, 3, len1(hyear))) + 1000
local wyear = frame:callParserFunction("padleft", {hebnum(sub1(hyear, 3, len1(hyear))) + 1000
* hebnum(sub1(hyear, 1, 2)) - 3761, 4 })
* hebnum(sub1(hyear, 1, 2)) - 3761, 4})
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
end


function opposite(gdate, format)
function opposite(gdate, format)
if samesame == true then
if samesame == true
samesame = false
then samesame = false
return format(gdate)
return format(gdate) end
end
end
end


function from(gdate)
function from(gdate)
local ans = opposite(gdate, to)
local ans = opposite(gdate, to)
if ans ~= nil then
if ans ~= nil
return ans
then return ans end
end
if frame.args["links"] == "yes"
if frame.args["links"] == "yes" then
then return "[[" .. frame:callParserFunction("#זמןמ:xhxjj xjx", gdate) .. "]] [["
return "[[" .. langObject:formatDate("xhxjj xjx", gdate) .. "]] [["
.. frame:callParserFunction("#זמןמ:xhxjY", gdate) .. "]]" end
.. langObject:formatDate("xhxjY", gdate) .. "]]"
return frame:callParserFunction("#זמןמ:xhxjj xjx xhxjY", gdate)
end
return langObject:formatDate("xhxjj xjx xhxjY", gdate)
end
end


function frommonth(gdate)
function frommonth(gdate)
local ans = opposite(gdate, tomonth)
local ans = opposite(gdate, tomonth)
if ans ~= nil then
if ans ~= nil
return ans
then return ans end
end
if frame.args["links"] == "yes"
if frame.args["links"] == "yes" then
then return "[[" .. frame:callParserFunction("#זמןמ:xjF", gdate) .. "]] [["
return "[[" .. langObject:formatDate("xjF", gdate) .. "]] [["
.. frame:callParserFunction("#זמןמ:xhxjY", gdate) .. "]]" end
.. langObject:formatDate("xhxjY", gdate) .. "]]"
return frame:callParserFunction("#זמןמ:xjF xhxjY", gdate)
end
return langObject:formatDate("xjF xhxjY", gdate)
end
end


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


function fromyear(gdate)
function fromyear(gdate)
local ans = opposite(gdate, toyear)
local ans = opposite(gdate, toyear)
if ans ~= nil then
if ans ~= nil
return ans
then return ans end
end
if frame.args["links"] == "yes"
if frame.args["links"] == "yes" then
then return "[[" .. frame:callParserFunction("#זמןמ:xhxjY", gdate) .. "]]" end
return "[[" .. langObject:formatDate("xhxjY", gdate) .. "]]"
return frame:callParserFunction("#זמןמ:xhxjY", gdate)
end
return langObject:formatDate("xhxjY", gdate)
end
end


function same(gdate)
function same(gdate)
return langObject:formatDate("d-m-Y", gdate)
return frame:callParserFunction("#זמןמ:d-m-Y", gdate)
end
end


function makeyear(gdate)
function makeyear(gdate)
local year = langObject:formatDate("Y", gdate)
local year = frame:callParserFunction("#זמןמ:Y", gdate)
if tonumber(year) < 1000 and which
if tonumber(year) < 1000 and which
then
then year = sub1(year, 2)
year = sub1(year, 2)
end
end
return year
return year
שורה 206: שורה 150:
function to(gdate)
function to(gdate)
local year = makeyear(gdate)
local year = makeyear(gdate)
if frame.args["links"] == "yes" then
if frame.args["links"] == "yes"
return "[[" .. langObject:formatDate("j בF", gdate) .. "]] [["
then return "[[" .. frame:callParserFunction("#זמןמ:j בF", gdate) .. "]] [["
.. year .. "]]"
.. year .. "]]" end
end
return frame:callParserFunction("#זמןמ:j בF", gdate) .. " " .. year
return langObject:formatDate("j בF", gdate) .. " " .. year
end
end


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


function toonlymonth(gdate)
function toonlymonth(gdate)
if frame.args["links"] == "yes" then
if frame.args["links"] == "yes"
return "[[" .. langObject:formatDate("F", gdate) .. "]]"
then return "[[" .. frame:callParserFunction("#זמןמ:F", gdate) .. "]]" end
end
return frame:callParserFunction("#זמןמ:F", gdate)
return langObject:formatDate("F", gdate)
end
end


function toyear(gdate)
function toyear(gdate)
local year = makeyear(gdate)
local year = makeyear(gdate)
if frame.args["links"] == "yes" then
if frame.args["links"] == "yes"
return "[[" .. year .. "]]"
then return "[[" .. year .. "]]" end
end
return year
return year
end
end
שורה 243: שורה 183:
for m, mm in pairs(typomonthtable) do
for m, mm in pairs(typomonthtable) do
point = find1(hdate, m)
point = find1(hdate, m)
if point > 0 and max < len1(m) then
if point > 0 and max < len1(m)
max = len1(m)
then max = len1(m)
place = m
place = m end
end
end
if max > 0 then
point = find1(hdate, place)
return sub1(hdate, 1, point - 1) .. typomonthtable[place] .. sub1(hdate, point + len1(place))
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
return hdate
end
end
שורה 257: שורה 195:
function fixdate(hdate1)
function fixdate(hdate1)
local hdate = fixmonth(hdate1)
local hdate = fixmonth(hdate1)
if 1 == find1(hdate, "ראש חודש") then
if 1 == find1(hdate, "ראש חודש")
hdate = "א' ב" .. sub1(hdate, 10)
then hdate = "א' ב" .. sub1(hdate, 10) end
end
local h1, h2, h3 = parts(hdate)
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)
שורה 272: שורה 209:
]=]
]=]
if (len1(h3) > 1 and sub1(h3, 2, 2) ~= "'") then
if (len1(h3) > 1 and sub1(h3, 2, 2) ~= "'") then
h3 = "ה'" .. h3
h3 = "ה'" .. h3 end
end
--[=[
--[=[
for m, mm in pairs(typomonthtable) do
for m, mm in pairs(typomonthtable) do
if h2 == "ב" .. m
if h2 == "ב" .. m
שורה 281: שורה 217:
]=]
]=]
for y, yy in pairs(lastletters) do
for y, yy in pairs(lastletters) do
if sub1(h3, len1(h3)) == y then
if sub1(h3, len1(h3)) == y
h3 = sub1(h3, 1, len1(h3) - 1) .. yy
then h3 = sub1(h3, 1, len1(h3) - 1) .. yy end
end
end
end
return { h1, h2, h3, h1 .. " " .. h2 .. " " .. h3 }
return {h1, h2, h3, h1 .. " " .. h2 .. " " .. h3}
end
end


function fixerror(message)
function fixerror(message)
if message == "---" then
if message == "---"
return ""
then return "" end
end
return frame:preprocess(message)
return frame:preprocess(message)
end
end
שורה 307: שורה 241:
for f, ff in pairs(mtable) do
for f, ff in pairs(mtable) do
if "ב" .. ff == h2 then
if "ב" .. ff == h2 then
return h1 .. "-" .. frame:callParserFunction("padleft", { f, 2 })
return h1 .. "-" .. frame:callParserFunction("padleft", {f, 2})
.. "-" .. frame:callParserFunction("padleft", { h3, 4 })
.. "-" .. frame:callParserFunction("padleft", {h3, 4}) end
end
end
end
end
end
שורה 316: שורה 249:
local s1 = find1(wdate, "-")
local s1 = find1(wdate, "-")
local s2 = find1(wdate, "-", s1 + 1)
local s2 = find1(wdate, "-", s1 + 1)
return { tonumber(sub1(wdate, 1, s1 - 1)),
return {tonumber(sub1(wdate, 1, s1 - 1)),
tonumber(sub1(wdate, s1 + 1, s2 - 1)),
tonumber(sub1(wdate, s1 + 1, s2 - 1)),
tonumber(sub1(wdate, s2 + 1, len1(wdate))) }
tonumber(sub1(wdate, s2 + 1, len1(wdate)))}
end
end


שורה 327: שורה 260:
local wmonth = wdate[2]
local wmonth = wdate[2]
local wyear = wdate[3]
local wyear = wdate[3]
if wyear > 1582 or (wyear == 1582 and (wmonth > 10 or (wmonth == 10 and wday > 14))) then
if wyear > 1582 or (wyear == 1582 and (wmonth > 10 or (wmonth == 10 and wday > 14)))
ans = 0
then ans = 0
else
else local ytable = {200, 300, 500, 600, 700, 900, 1000, 1100, 1300, 1400, 1500}
local ytable = { 200, 300, 500, 600, 700, 900, 1000, 1100, 1300, 1400, 1500 }
ans = 10
ans = 10
if wmonth < 3
if wmonth < 3 then
then wyear = wyear - 1 end
wyear = wyear - 1
for y, yy in pairs(ytable) do
end
if yy > wyear
for y, yy in pairs(ytable) do
then ans = ans - 1 end
if yy > wyear then
end end
ans = ans - 1
end
end
end
return ans
return ans
end
end


function remove(dateStr) -- Thanks to Eran
function remove(dateStr) -- Thanks to Eran
dateStr = mw.ustring.gsub(dateStr, "[%[%]]", "")
dateStr = mw.ustring.gsub( dateStr, "[%[%]]", "" )
dateStr = mw.ustring.gsub(dateStr, "(\127UNIQ[^\127]+QINU\127)", "")
dateStr = mw.ustring.gsub(dateStr, "(\127UNIQ[^\127]+QINU\127)", "")
dateStr = mw.ustring.gsub(dateStr, "&rlm;", "")
dateStr = mw.ustring.gsub(dateStr, "&rlm;","")
dateStr = mw.ustring.gsub(dateStr, "&lrm;", "")
dateStr = mw.ustring.gsub(dateStr, "&lrm;","")
return dateStr
return dateStr
end
end
שורה 355: שורה 284:
local wnumbers = numtonums(wdate)
local wnumbers = numtonums(wdate)
if wnumbers[3] < 360 or wnumbers[3] > 4357 or
if wnumbers[3] < 360 or wnumbers[3] > 4357 or
(wnumbers[3] == 1582 and wnumbers[2] == 10 and wnumbers[1] > 4 and wnumbers[1] < 15)
(wnumbers[3] == 1582 and wnumbers[2] == 10 and wnumbers[1] > 4 and wnumbers[1] < 15)
then
then error("The date is not in the allowed casp", 0) end
error("The date is not in the allowed casp", 0)
end
end
end


function fromhebrewyear(hyear)
function fromhebrewyear(hyear)
ans = fromhebrewdate("א' בניסן " .. hyear, toyear)
ans = fromhebrewdate("א' בניסן " .. hyear, toyear)
if frame.args["exact"] ~= "כן" then
if frame.args["exact"] ~= "כן"
ans = ans .. "-" .. fromhebrewdate("א' בתשרי " .. hyear, toyear)
then ans = ans .. "-" .. fromhebrewdate("א' בתשרי " .. hyear, toyear)
end
end
return ans
return ans
שורה 370: שורה 297:


function fromhebrewmonth(hdate)
function fromhebrewmonth(hdate)
if frame.args["exact"] == "כן" then
if frame.args["exact"] == "כן"
return fromhebrewdate('ט"ו ב' .. hdate, tomonth)
then return fromhebrewdate('ט"ו ב' .. hdate, tomonth) end
end
local date1 = fromhebrewdate("א' ב" .. hdate, same)
local date1 = fromhebrewdate("א' ב" .. hdate, same)
local month1 = toonlymonth(date1)
local month1 = toonlymonth(date1)
שורה 382: שורה 308:
local month2 = toonlymonth(date2)
local month2 = toonlymonth(date2)
local year2 = toyear(date2)
local year2 = toyear(date2)
if year1 ~= year2 then
if year1 ~= year2
return month1 .. " " .. year1 .. " - " .. month2 .. " " .. year2
then return month1 .. " " .. year1 .. " - " .. month2 .. " " .. year2
elseif month1 ~= month2 then
elseif month1 ~= month2
return month1 .. "-" .. month2 .. " " .. year1
then return month1 .. "-" .. month2 .. " " .. year1
else
else return month1 .. " " .. year1 end
return month1 .. " " .. year1
end
end
end


שורה 398: שורה 322:
function fromhebrew1(hdate)
function fromhebrew1(hdate)
local ht, rem = findhdatetype(fixmonth(hdate))
local ht, rem = findhdatetype(fixmonth(hdate))
if ht == "dmy" then
if ht == "dmy"
return ifwhich(fromhebrewdate(rem, to))
then return ifwhich(fromhebrewdate(rem, to))
elseif ht == "my" then
elseif ht == "my"
return ifwhich(fromhebrewmonth(rem))
then return ifwhich(fromhebrewmonth(rem))
elseif ht == "y" then
elseif ht == "y"
return ifwhich(fromhebrewyear(rem))
then return ifwhich(fromhebrewyear(rem))
else
else error("Wrong type: " .. ht, 0) end
error("Wrong type: " .. ht, 0)
end
end
end


שורה 412: שורה 334:
local rem = mw.text.trim(remove(hdate))
local rem = mw.text.trim(remove(hdate))
local day, month, year = parts(hdate)
local day, month, year = parts(hdate)
if day ~= nil then
if day ~= nil
return "dmy", rem
then return "dmy", rem end
end
if month ~= nil
if month ~= nil then
then return "my", rem end
return "my", rem
end
return "y", rem
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
שורה 445: שורה 365:
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], "[[קטגוריה:חוסר מתאם בין תאריך עברי לתאריך לועזי]]")
if not success then
if not success
res = ""
then res = "" end
end
local ans = ""
local ans = ""
if f.args[2] ~= "" then
if f.args[2] ~= ""
ans = tohebrew0(f.args[2])
then ans = tohebrew0(f.args[2]) end
end
if f.args[1] ~= ""
if f.args[1] ~= "" then
then ans = ans .. fromhebrewandverify(f) end
ans = ans .. fromhebrewandverify(f)
end
return res .. ans
return res .. ans
end
end
שורה 461: שורה 378:
frame = f
frame = f
local success, res = pcall(fromhebrew1, frame.args[1])
local success, res = pcall(fromhebrew1, frame.args[1])
if success then
if success
return ifwhich(res)
then return ifwhich(res)
elseif frame.args["about"] == "כן" and
elseif frame.args["about"] == "כן" and
frame:expandTemplate({ title = "גיל לערכי אישים/מקורב", args = { str = frame.args[1] } }) ~= "" then
frame:expandTemplate({title = "גיל לערכי אישים/מקורב", args = {str = frame.args[1]}}) ~= ""
return ifwhich(frame.args[1], "[[קטגוריה:דפים עם תאריך עברי מקורב]]")
then return ifwhich(frame.args[1], "[[קטגוריה:דפים עם תאריך עברי מקורב]]")
elseif frame.args["error"] == nil then
elseif frame.args["error"] == nil
return aserror(res)
then return aserror(res) end
end
return fixerror(frame.args["error"])
return fixerror(frame.args["error"])
end
end
שורה 474: שורה 390:
function tohebrewyear(gyear)
function tohebrewyear(gyear)
ans = tohebrewnum("01-01-" .. gyear, fromyear)
ans = tohebrewnum("01-01-" .. gyear, fromyear)
if frame.args["exact"] ~= "כן" then
if frame.args["exact"] ~= "כן"
ans = ans .. "-" .. tohebrewnum("01-12-" .. gyear, fromyear)
then ans = ans .. "-" .. tohebrewnum("01-12-" .. gyear, fromyear)
end
end
return ifwhich(ans)
return ifwhich(ans)
שורה 481: שורה 397:


function tohebrewmonth(wdate)
function tohebrewmonth(wdate)
if frame.args["exact"] == "כן" then
if frame.args["exact"] == "כן"
return tohebrewdate("15 ב" .. wdate, frommonth)
then return tohebrewdate("15 ב" .. wdate, frommonth) end
end
local date1 = tohebrewdate("1 ב" .. wdate, same)
local date1 = tohebrewdate("1 ב" .. wdate, same)
local month1 = fromonlymonth(date1)
local month1 = fromonlymonth(date1)
שורה 493: שורה 408:
local month2 = fromonlymonth(date2)
local month2 = fromonlymonth(date2)
local year2 = fromyear(date2)
local year2 = fromyear(date2)
if year1 ~= year2 then
if year1 ~= year2
return ifwhich(month1 .. " " .. year1 .. " - " .. month2 .. " " .. year2)
then return ifwhich(month1 .. " " .. year1 .. " - " .. month2 .. " " .. year2)
elseif month1 ~= month2 then
elseif month1 ~= month2
return ifwhich(month1 .. "-" .. month2 .. " " .. year1)
then return ifwhich(month1 .. "-" .. month2 .. " " .. year1)
else
else return ifwhich(month1 .. " " .. year1) end
return ifwhich(month1 .. " " .. year1)
end
end
end


שורה 505: שורה 418:
local s1 = find1(rem, " ")
local s1 = find1(rem, " ")
local s2 = find1(rem, " ", s1 + 1)
local s2 = find1(rem, " ", s1 + 1)
if len1(rem) - s2 == 3 then
if len1(rem) - s2 == 3
rem = sub1(rem, 1, s2) .. "0" .. sub1(rem, s2 + 1)
then rem = sub1(rem, 1, s2) .. "0" .. sub1(rem, s2 + 1) end
end
local take = takenumbers(rem)
local take = takenumbers(rem)
if remove(to(take)) ~= rem then
if remove(to(take)) ~= rem
error("wrong date", 0)
then error("wrong date", 0) end
end
checkcasp(take)
checkcasp(take)
take = same(take .. " + " .. diff(take) .. " days")
take = same(take .. " + " .. diff(take) .. " days")
שורה 518: שורה 429:


function tohebrewnum(wdate, format)
function tohebrewnum(wdate, format)
if find1(wdate, "-", 3) == 3 and find1(wdate, "-", 6) == 6 and len1(wdate) == 9 then
if find1(wdate, "-", 3) == 3 and find1(wdate, "-", 6) == 6 and len1(wdate) == 9
wdate = sub1(wdate, 1, 6) .. "0" .. sub1(wdate, 7, 9)
then wdate = sub1(wdate, 1, 6) .. "0" .. sub1(wdate, 7, 9) end
end
if same(wdate) ~= wdate
if same(wdate) ~= wdate then
then error("wrong date", 0) end
error("wrong date", 0)
end
checkcasp(wdate)
checkcasp(wdate)
wdate = same(wdate .. " + " .. diff(wdate) .. " days")
wdate = same(wdate .. " + " .. diff(wdate) .. " days")
שורה 532: שורה 441:
local rem = mw.text.trim(remove(wdate))
local rem = mw.text.trim(remove(wdate))
if find1(rem, "-") ~= 0 then
if find1(rem, "-") ~= 0 then
return "num", rem
return "num", rem end
end
for m, mm in pairs(mtable) do
for m, mm in pairs(mtable) do
if find1(rem, mm) == 1 then
if find1(rem, mm) == 1 then
return "my", rem
return "my", rem end
end
end
end
if tonumber(rem) ~= nil and tonumber(rem) .. "" == rem then
if tonumber(rem) ~= nil and tonumber(rem) .. "" == rem then
return "y", rem
return "y", rem end
end
return "dmy", rem
return "dmy", rem
end
end
שורה 547: שורה 453:
function tohebrew1(wdate)
function tohebrew1(wdate)
local w, rem = findwdatetype(wdate)
local w, rem = findwdatetype(wdate)
if w == "num" then
if w == "num"
return tohebrewnum(rem, from)
then return tohebrewnum(rem, from)
elseif w == "dmy" then
elseif w == "dmy"
return tohebrewdate(rem, from)
then return tohebrewdate(rem, from)
elseif w == "my" then
elseif w == "my"
return tohebrewmonth(rem)
then return tohebrewmonth(rem)
elseif w == "y" then
elseif w == "y"
return tohebrewyear(rem)
then return tohebrewyear(rem)
else
else error("Wrong type: " .. ht, 0) end
error("Wrong type: " .. ht, 0)
end
end
end


function pick1(hdate, wdate, cat)
function pick1(hdate, wdate, cat)
local ht, wt, hrem, wrem, hdw, wdh, hsuccess, wsuccess, thsuccess, twsuccess
local ht, wt, hrem, wrem, hdw, wdh, hsuccess, wsuccess, thsuccess, twsuccess
if cat == nil then
if cat == nil
which = true
then which = true
ht, hrem = findhdatetype(hdate)
ht, hrem = findhdatetype(hdate)
wt, wrem = findwdatetype(wdate)
wt, wrem = findwdatetype(wdate)
else
else thsuccess, ht, hrem = pcall(findhdatetype, hdate)
thsuccess, ht, hrem = pcall(findhdatetype, hdate)
twsuccess, wt, wrem = pcall(findwdatetype, wdate)
twsuccess, wt, wrem = pcall(findwdatetype, wdate)
hsuccess = false
hsuccess = false
wsuccess = false end
wsuccess = false
if hrem == ""
end
then ht = "empty"
if hrem == "" then
else hsuccess, hdw = pcall(fromhebrew1, hrem)
ht = "empty"
if not hsuccess
else
then ht = "about" end end
hsuccess, hdw = pcall(fromhebrew1, hrem)
if wrem == ""
if not hsuccess then
then wt = "empty"
ht = "about"
else wsuccess, wdh = pcall(tohebrew1, wrem)
end
if not wsuccess
end
then wt = "about" end end
if wrem == "" then
if cat ~= nil
wt = "empty"
then if ht == "dmy" and wt ~= "dmy"
else
then return "[[קטגוריה:חוסר מתאם בתאריכים - תאריך "  
wsuccess, wdh = pcall(tohebrew1, wrem)
.. frame.args["type"] .. " עברי מדויק]]" end
if not wsuccess then
if ht ~= "dmy" and wt == "dmy"
wt = "about"
then return "[[קטגוריה:חוסר מתאם בתאריכים - תאריך "  
end
.. frame.args["type"] .. " לועזי מדויק]]" end
end
-- if ht == "dmy" or ht == "my" or ht == "y"
if cat ~= nil then
-- then return "[[קטגוריה:חוסר מתאם בתאריכים - תאריך "  
if ht == "dmy" and wt ~= "dmy"
-- .. frame.args["type"] .. " לועזי מדויק]]" end
then
return "" end
return "[[קטגוריה:חוסר מתאם בתאריכים - תאריך "
if wsuccess and hsuccess
.. frame.args["type"] .. " עברי מדויק]]"
then if wt == "dmy" then return wdate
end
elseif ht == "dmy" then return hdw
if ht ~= "dmy" and wt == "dmy" then
elseif wt == "my" then return wdate
return "[[קטגוריה:חוסר מתאם בתאריכים - תאריך "
elseif ht == "my" then return hdw
.. frame.args["type"] .. " לועזי מדויק]]"
elseif wt == "y" then return wdate
end
else return hdw end
-- if ht == "dmy" or ht == "my" or ht == "y"
elseif wsuccess then return wdate
-- then return "[[קטגוריה:חוסר מתאם בתאריכים - תאריך "
elseif hsuccess then return hdw
-- .. frame.args["type"] .. " לועזי מדויק]]" end
elseif wt == "about" then return wdate
return ""
else return hdate end
end
if wsuccess and hsuccess then
if wt == "dmy" then
return wdate
elseif ht == "dmy" then
return hdw
elseif wt == "my" then
return wdate
elseif ht == "my" then
return hdw
elseif wt == "y" then
return wdate
else
return hdw
end
elseif wsuccess then
return wdate
elseif hsuccess then
return hdw
elseif wt == "about" then
return wdate
else
return hdate
end
end
end


function checkcat(adate, cat)
function checkcat(adate, cat)
if cat == nil then
if cat == nil
return adate
then return adate end
end
return cat
return cat
end
end
שורה 641: שורה 520:
local habout = false
local habout = false
local wabout = false
local wabout = false
if frame:expandTemplate({ title = "גיל לערכי אישים/מקורב", args = { str = hebrew } }) ~= ""
if frame:expandTemplate({title = "גיל לערכי אישים/מקורב", args = {str = hebrew}}) ~= ""
then
then hebrew = ""
hebrew = ""
habout = true end
habout = true
if frame:expandTemplate({title = "גיל לערכי אישים/מקורב", args = {str = world}}) ~= ""
end
then world = ""
if frame:expandTemplate({ title = "גיל לערכי אישים/מקורב", args = { str = world } }) ~= ""
wabout = true end
then
world = ""
wabout = true
end
local success, res = pcall(pick1, hebrew, world)
local success, res = pcall(pick1, hebrew, world)
if success then
if success
if habout and world == "" then
then if habout and world == ""
return frame.args["hebrew"]
then return frame.args["hebrew"] end
end
if wabout and hebrew == ""
if wabout and hebrew == "" then
then return frame.args["world"] end
return frame.args["world"]
return res
end
elseif frame.args["error"] == nil
return res
then return aserror(res) end
elseif frame.args["error"] == nil then
return aserror(res)
end
return fixerror(frame.args["error"])
return fixerror(frame.args["error"])
end
end
שורה 668: שורה 540:
function tohebrew0(wdate)
function tohebrew0(wdate)
local success, res = pcall(tohebrew1, wdate)
local success, res = pcall(tohebrew1, wdate)
if success then
if success
return res
then return res
elseif frame.args["about"] == "כן" and
elseif frame.args["about"] == "כן" and
frame:expandTemplate({ title = "גיל לערכי אישים/מקורב", args = { str = wdate } }) ~= "" then
frame:expandTemplate({title = "גיל לערכי אישים/מקורב", args = {str = wdate}}) ~= ""
return ifwhich(frame.args[1], "[[קטגוריה:דפים עם תאריך מקורב]]")
then return ifwhich(frame.args[1], "[[קטגוריה:דפים עם תאריך מקורב]]")
elseif frame.args["error"] == nil then
elseif frame.args["error"] == nil
return aserror(res)
then return aserror(res) end
end
return fixerror(frame.args["error"])
return fixerror(frame.args["error"])
end
end
שורה 693: שורה 564:


function ifwhich(ans, noans)
function ifwhich(ans, noans)
if noans == nil then
if noans == nil
noans = ""
then noans = "" end
end
if which
if which then
then return ans
return ans
else return noans end
else
return noans
end
end
end


function parts(hdate)
function parts(hdate)
local funcs = {
local funcs = {
{ function() return w[1] end },
{function() return w[1] end},
{ function() return w[2], w[1] end,
{function() return w[2], w[1] end,
function() return c(w[2], w[1]) end },
function() return c(w[2], w[1]) end},
{ function() return w[3], 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 c(w[3], w[2]), w[1] end,
function() return w[3], c(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 w[4], c(w[3], w[2]), w[1] end,
function() return c(w[4], w[3]), w[2], w[1] end,
function() return c(w[4], w[3]), w[2], w[1] end,
nil,
nil,
function() return c(w[4], w[3]), c(w[2], w[1]) end },
function() return c(w[4], w[3]), c(w[2], w[1]) end},
{ nil,
{nil,
function() return c(w[5], w[4]), c(w[3], w[2]), w[1] end } }
function() return c(w[5], w[4]), c(w[3], w[2]), w[1] end}}
function c(x, y) return y .. " " .. x end
function c(x, y) return y .. " " .. x end
w = takewords(hdate)
w = takewords(hdate)
local code = 1
local code = 1
if 0 < find1(hdate, "אלפים") then
if 0 < find1(hdate, "אלפים")
code = code + 1
then code = code + 1 end
end
if 1 == find1(hdate, "אדר א")
if 1 == find1(hdate, "אדר א") then
then code = code + 2 end
code = code + 2
if 1 == find1(hdate, "אדר ב")
end
then code = code + 2 end
if 1 == find1(hdate, "אדר ב") then
code = code + 2
end
local year, month, day = funcs[#w][code]()
local year, month, day = funcs[#w][code]()
return day, month, year
return day, month, year
שורה 747: שורה 611:
end
end


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