יחידה:תאריך עברי: הבדלים בין גרסאות בדף
מראה
אין תקציר עריכה |
אין תקציר עריכה |
||
| שורה 7: | שורה 7: | ||
local where = 1; | local where = 1; | ||
if (args ~= nil) then | if (args ~= nil) then | ||
where = args | where = args end | ||
local ans = mw.ustring.find(str, what, where, true); | local ans = mw.ustring.find(str, what, where, true); | ||
if (ans == nil) then | if (ans == nil) then | ||
ans = 0 | ans = 0 end | ||
return ans | return ans | ||
end | end | ||
| שורה 18: | שורה 16: | ||
function len1(s) | function len1(s) | ||
if (s == nil) then | if (s == nil) then | ||
return 0 | return 0 end | ||
return mw.ustring.len(s) | return mw.ustring.len(s) | ||
end | end | ||
| שורה 30: | שורה 27: | ||
["נ"] = 50, ["ן"] = 50, ["ס"] = 60, ["ע"] = 70, ["פ"] = 80, | ["נ"] = 50, ["ן"] = 50, ["ס"] = 60, ["ע"] = 70, ["פ"] = 80, | ||
["ף"] = 80, ["צ"] = 90, ["ץ"] = 90, ["ק"] = 100, ["ר"] = 200, | ["ף"] = 80, ["צ"] = 90, ["ץ"] = 90, ["ק"] = 100, ["ר"] = 200, | ||
["ש"] = 300, ["ת"] = 400, ["'"] = 0, ["\""] = 0, | ["ש"] = 300, ["ת"] = 400, ["'"] = 0, ["\""] = 0,} | ||
local ans = 0 | local ans = 0 | ||
local str = s | local str = s | ||
| שורה 43: | שורה 39: | ||
function mindate(fix, frame) | function mindate(fix, frame) | ||
local monthtable = { | local 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, | |||
} | } | ||
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} | ||
| שורה 68: | שורה 54: | ||
while (count < 82) do | while (count < 82) do | ||
if (from(mindate .. " + " .. count .. " days", frame) == hdate) then | if (from(mindate .. " + " .. count .. " days", frame) == hdate) then | ||
return to1(mindate .. " + " .. count .. " days", frame) | return to1(mindate .. " + " .. count .. " days", frame) end | ||
count = count + 1 | count = count + 1 | ||
end | end | ||
| שורה 92: | שורה 77: | ||
local s3 = find1(hdate, " ", s2 + 1); | local s3 = find1(hdate, " ", s2 + 1); | ||
if (s3 > 0) then | if (s3 > 0) then | ||
s2 = s3 | s2 = s3 end | ||
h1 = sub1(hdate, 1, s1 - 1) | h1 = sub1(hdate, 1, s1 - 1) | ||
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 | h3 = "ה'" .. h3 end | ||
return {h1, h2, h3, h1 .. " " .. h2 .. " " .. h3} | return {h1, h2, h3, h1 .. " " .. h2 .. " " .. h3} | ||
end | end | ||
| שורה 119: | שורה 102: | ||
for f, ff in pairs(mtable) do | for f, ff in pairs(mtable) do | ||
if ff == h2 then | if ff == h2 then | ||
return h1 .. "-" .. f .. "-" .. frame:callParserFunction("padleft", {h3, 4}) | return h1 .. "-" .. f .. "-" .. frame:callParserFunction("padleft", {h3, 4}) end | ||
end | end | ||
return wdate | return wdate | ||
| שורה 144: | שורה 126: | ||
local wyear = wdate[3] | local wyear = wdate[3] | ||
if wyear > 1582 or (wyear == 1582 and (wmonth > 10 or (wmonth == 10 and wday > 14))) | if wyear > 1582 or (wyear == 1582 and (wmonth > 10 or (wmonth == 10 and wday > 14))) | ||
then ans = 0 else | then ans = 0 | ||
else local ytable = {200, 300, 500, 600, 700, 900, 1000, 1100, 1300, 1400, 1500} | |||
ans = 10 | |||
for y, yy in pairs(ytable) do | |||
if yy > wyear | |||
then ans = ans - 1 end | |||
end end | |||
return wday .. "-" .. wmonth .. "-" .. wyear .. ": " .. ans | return wday .. "-" .. wmonth .. "-" .. wyear .. ": " .. ans | ||
end | end | ||
גרסה מ־18:29, 15 במאי 2015
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 hebnum(s)
numberstable = {
["א"] = 1, ["ב"] = 2, ["ג"] = 3, ["ד"] = 4, ["ה"] = 5,
["ו"] = 6, ["ז"] = 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 str = s
while len1(str) > 0 do
ans = ans + numberstable[sub1(str, 1, 1)]
str = sub1(str, 2, len1(str))
end
return ans
end
function mindate(fix, frame)
local monthtable = {
["בתשרי"] = 7, ["בחשוון"] = 8, ["בכסלו"] = 9, ["בטבת"] = 10,
["בשבט"] = 11, ["באדר א'"] = 12, ["באדר ב'"] = 13, ["באדר"] = 13,
["בניסן"] = 1, ["באייר"] = 2, ["בסיוון"] = 3, ["בתמוז"] = 4,
["באב"] = 5, ["באלול"] = 6,
}
local indenttable = {176, 206, 235, 265, 294, 324, 0, 30, 59, 88, 117, 147, 147}
return to("28-08-" .. frame:callParserFunction("padleft", {hebnum(sub1(fix[3], 3, len1(fix[3]))) + 1000
* hebnum(sub1((fix[3]), 1, 2)) - 3761, 4}) .. " + " .. (indenttable[monthtable[fix[2]]]
+ hebnum(fix[1]) - 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 fromhebrew(frame)
local hdate = remove(frame.args[1])
local fix = fixdate(hdate)
return exacttdate(fix[4], mindate(fix, frame), frame)
end
function takenumbers(wdate, frame)
local s1 = find1(wdate, " ")
local s2 = find1(wdate, " ", s1 + 1)
local h1 = sub1(wdate, 1, s1 - 1)
local h2 = sub1(wdate, s1 + 1, s2 - 1)
local h3 = sub1(wdate, s2 + 1, len1(wdate))
mtable = {"בינואר", "בפברואר", "במרץ", "באפריל", "במאי", "ביוני",
"ביולי", "באוגוסט", "בספטמבר", "באוקטובר", "בנובמבר", "בדצמבר", }
for f, ff in pairs(mtable) do
if ff == h2 then
return h1 .. "-" .. f .. "-" .. frame:callParserFunction("padleft", {h3, 4}) end
end
return wdate
end
function numtonums(wdate)
local s1 = find1(wdate, "-")
local s2 = find1(wdate, "-", s1 + 1)
return {tonumber(sub1(wdate, 1, s1 - 1)),
tonumber(sub1(wdate, s1 + 1, s2 - 1)),
tonumber(sub1(wdate, s2 + 1, len1(wdate)))}
end
function tohebrew(frame)
return from(takenumbers(remove(frame.args[1]), frame), frame)
end
function diff(frame)
local ans
local wdate = numtonums(frame.args[1])
local wday = wdate[1]
local wmonth = wdate[2]
local wyear = wdate[3]
if wyear > 1582 or (wyear == 1582 and (wmonth > 10 or (wmonth == 10 and wday > 14)))
then ans = 0
else local ytable = {200, 300, 500, 600, 700, 900, 1000, 1100, 1300, 1400, 1500}
ans = 10
for y, yy in pairs(ytable) do
if yy > wyear
then ans = ans - 1 end
end end
return wday .. "-" .. wmonth .. "-" .. wyear .. ": " .. ans
end
function remove(dateStr) -- Thanks to Eran
dateStr = mw.ustring.gsub( dateStr, "[%[%]]", "" )
dateStr = mw.ustring.gsub(dateStr, "(\127UNIQ[^\127]+QINU\127)", "")
dateStr = mw.ustring.gsub(dateStr, "‏","")
dateStr = mw.ustring.gsub(dateStr, "‎","")
return dateStr
end
return {fromhebrew = fromhebrew, tohebrew = tohebrew, diff = diff}