מייבאים כמותיים, בדוקי עריכות אוטומטית, אינטערפעיס אדמיניסטראַטאָרן, מנטרים, מייבאים, מעדכנים, אספקלריה רעדאקטארן
3,951
רעדאגירונגען
אין תקציר עריכה |
אין תקציר עריכה |
||
| שורה 3: | שורה 3: | ||
-- פונקציית עזר – החזרת אות בעברית או מספר | -- פונקציית עזר – החזרת אות בעברית או מספר | ||
local function gim(n) | local function gim(n) | ||
if n > 10 then | |||
error("gim: input out of range (must be 1–10), got " .. tostring(n)) | |||
end | |||
local a = "אבגדהוזחכש" | local a = "אבגדהוזחכש" | ||
return mw.ustring.sub(a, n, n) | return mw.ustring.sub(a, n, n) | ||
end | end | ||
-- | -- Private: Compute Rosh Hashanah dates (JDN) for year and year+1 | ||
local function rosh_pair(y) | |||
local | local parts = 38004 + 765433 * math.floor((235 * y - 234) / 19) | ||
local days = math.floor(parts / 25920) | |||
local part_rem = parts % 25920 | |||
local | local weekday = 1 + (days % 7) | ||
local | |||
local | |||
if ( | local ibur1 = math.floor(((7 * y + 13) % 19) / 12) | ||
local ibur2 = math.floor(((7 * y + 6) % 19) / 12) | |||
if (part_rem >= 16404 and weekday == 3 and ibur1 == 0) | |||
or (part_rem >= 23269 and weekday == 2 and ibur2 == 1) then | |||
days = days + 1 | |||
part_rem = part_rem - 25920 | |||
end | end | ||
local | local jdn1 = days + ((days + 5) % 7) % 2 | ||
parts = part_rem + 9516 + (13753 * ibur1) | |||
days = days + math.floor(parts / 25920) + 354 + 29 * ibur1 | |||
part_rem = parts % 25920 | |||
weekday = 1 + (days % 7) | |||
ibur2 = math.floor(((7 * y + 1) % 19) / 12) | |||
if ( | if (part_rem >= 16404 and weekday == 3 and ibur2 == 0) | ||
or (part_rem >= 23269 and weekday == 2 and ibur1 == 1) then | |||
days = days + 1 | |||
end | end | ||
local | local jdn2 = days + ((days + 5) % 7) % 2 | ||
return { jdn1, jdn2 } | |||
end | |||
local | -- Convert JDN to Gregorian/Julian MM/DD | ||
local function jd_to_date(j, julian) | |||
local f = j + 1401 | |||
if not julian then | |||
f = f + math.floor((math.floor((4 * j + 274277) / 146097) * 3) / 4) - 38 | |||
end | |||
local e = 4 * f + 3 | |||
local g = math.floor((e % 1461) / 4) | |||
local h = 5 * g + 2 | |||
local month = ((math.floor(h / 153) + 2) % 12) + 1 | |||
local day = math.floor((h % 153) / 5) + 1 | |||
return month .. "/" .. day | |||
end | |||
-- מקבלת שנה עברית ומחזירה סימן (למשל "הכז") | |||
p["סימן"] = function(frame) | |||
local y = tonumber(frame.args[1] or frame.args["year"]) | |||
if not y then return "Invalid year" end | |||
local roshs = rosh_pair(y) | |||
return gim((roshs[1] % 7) + 1) .. | |||
gim(((roshs[2] - roshs[1]) % 10) + 5) .. | |||
gim(((roshs[2] - 2) % 7) + 1) | |||
end | |||
-- אפשניט אין ציווילע קאלענדערס | |||
p["אפשניט"] = function(frame) | |||
local y = tonumber(frame.args[1] or frame.args["year"]) | |||
local c = frame.args[2] or frame.args["cal"] | |||
if not y then return "Invalid year" end | |||
if not c then return "Missing calendar type" end | |||
local roshs = rosh_pair(y) | |||
if c == "ג" then | |||
return jd_to_date(roshs[1]) .. "-" .. jd_to_date(roshs[2]) | |||
elseif c == "י" then | |||
return jd_to_date(roshs[1], true) .. "-" .. jd_to_date(roshs[2], true) | |||
elseif c == "ה" then | |||
if y <= 5342 then | |||
return jd_to_date(roshs[1], true) .. "-" .. jd_to_date(roshs[2], true) | |||
elseif y >= 5344 then | |||
return jd_to_date(roshs[1]) .. "-" .. jd_to_date(roshs[2]) | |||
elseif y == 5343 then | |||
return jd_to_date(roshs[1], true) .. "-" .. jd_to_date(roshs[2]) | |||
end | |||
end | |||
return "Invalid" | |||
end | |||
return p | return p | ||
רעדאגירונגען