35,340
עריכות
אין תקציר עריכה |
(שחזור לגרסה 488096 מ־08:22, 5 ביולי 2024 מאת עמד) |
||
שורה 1: | שורה 1: | ||
local p = {} | local p = {} | ||
function | local function is_leap(year) | ||
-- הפונקציה מקבלת שנה עברית בתור מספר ומחזירה ערך בוליאני האם היא מעוברת | -- הפונקציה מקבלת שנה עברית בתור מספר ומחזירה ערך בוליאני האם היא מעוברת | ||
local leap_year = {0, 3, 6, 8, 11, 14, 17, 19} -- השנים המעוברות בתוך מחזור של 19 שנה | local leap_year = {0, 3, 6, 8, 11, 14, 17, 19} -- השנים המעוברות בתוך מחזור של 19 שנה | ||
שורה 11: | שורה 11: | ||
end | end | ||
function | local function moladTishrei(year) | ||
-- הפונקציה מקבלת שנה עברית בתור מספר ומחזירה את המולד של תשרי בתור טבלה | -- הפונקציה מקבלת שנה עברית בתור מספר ומחזירה את המולד של תשרי בתור טבלה | ||
local years = (year - 1) % 19 -- מספר השנים במחזור שלפני השנה הזו | local years = (year - 1) % 19 -- מספר השנים במחזור שלפני השנה הזו | ||
local months = (year - 1 - years) * 235 / 19 -- מספר החודשים בכל המחזורים מבריאת העולם | local months = (year - 1 - years) * 235 / 19 -- מספר החודשים בכל המחזורים מבריאת העולם | ||
for y = 1, years do -- הוספת החודשים של המחזור הנוכחי לסכום | for y = 1, years do -- הוספת החודשים של המחזור הנוכחי לסכום | ||
if | if is_leap(y) | ||
then months = months + 13 | then months = months + 13 | ||
else months = months + 12 end | else months = months + 12 end | ||
שורה 29: | שורה 29: | ||
end | end | ||
function | local function first_day(year) | ||
-- מקבלת שנה עברית בתור מספר ומחזירה את היום שבו יחול ראש השנה | -- מקבלת שנה עברית בתור מספר ומחזירה את היום שבו יחול ראש השנה | ||
local molad = | local molad = moladTishrei(year) | ||
local day, hours, parts = molad[1], molad[2], molad[3] | local day, hours, parts = molad[1], molad[2], molad[3] | ||
local old_molad = hours > 18 or (hours == 18 and parts > 0) -- מולד זקן | local old_molad = hours > 18 or (hours == 18 and parts > 0) -- מולד זקן | ||
local g_t_rd = day == 3 and (hours > 9 or (hours == 9 and parts >= 204)) and not | local g_t_rd = day == 3 and (hours > 9 or (hours == 9 and parts >= 204)) and not is_leap(year) -- ג'-ט'-ר"ד בשנה פשוטה | ||
local b_tv_tkpt = | local b_tv_tkpt = is_leap(year - 1) and day == 2 and (hours > 15 or (hours == 15 and parts >= 589)) -- ב'-ט"ו-תקפ"ט אחר עיבור | ||
if old_molad or g_t_rd or b_tv_tkpt then day = day + 1 end | if old_molad or g_t_rd or b_tv_tkpt then day = day + 1 end | ||
if day == 8 then day = 2 end | if day == 8 then day = 2 end | ||
שורה 42: | שורה 42: | ||
end | end | ||
function | local function year_type(year) | ||
-- מקבלת שנה עברית בתור מספר ומחזירה את הסוג של השנה כמחרוזת | -- מקבלת שנה עברית בתור מספר ומחזירה את הסוג של השנה כמחרוזת | ||
local difference = ( | local difference = (first_day(year + 1) + 7 - first_day(year)) % 7 | ||
if difference == 0 then difference = 7 end | if difference == 0 then difference = 7 end | ||
if difference == 3 or ( | if difference == 3 or (is_leap(year) and difference == 5) then return "חסרה" end | ||
if difference == 4 or difference == 6 then return "כסדרה" end | if difference == 4 or difference == 6 then return "כסדרה" end | ||
if (difference == 5 and not | if (difference == 5 and not is_leap(year)) or difference == 7 then return "שלמה" end | ||
end | end | ||
function | local function days_a_month(year, month) | ||
-- מקבלת שנה עברית בתור מספר וחודש בתור מחרוזת ומחזירה את מספר הימים בו | -- מקבלת שנה עברית בתור מספר וחודש בתור מחרוזת ומחזירה את מספר הימים בו | ||
local full_months = {"תשרי", "שבט", "אדר א'", "ניסן", "סיוון", "אב"} | local full_months = {"תשרי", "שבט", "אדר א'", "ניסן", "סיוון", "אב"} | ||
שורה 62: | שורה 62: | ||
end | end | ||
if month == "חשוון" then | if month == "חשוון" then | ||
if | if year_type(year) == "שלמה" then return 30 else return 29 end | ||
end | end | ||
if month == "כסלו" then | if month == "כסלו" then | ||
if | if year_type(year) == "חסרה" then return 29 else return 30 end | ||
end | end | ||
end | end | ||
function | local function return_month(year, month, previous) | ||
-- מקבלת שנה עברית בתור מספר וחודש בתור מחרוזת ומחזירה את החודש הקודם או הבא | -- מקבלת שנה עברית בתור מספר וחודש בתור מחרוזת ומחזירה את החודש הקודם או הבא | ||
local months = {"תשרי", "חשון", "כסלו", "טבת", "שבט", "אדר", "ניסן", "אייר", "סיון", "תמוז", "אב", "אלול"} | local months = {"תשרי", "חשון", "כסלו", "טבת", "שבט", "אדר", "ניסן", "אייר", "סיון", "תמוז", "אב", "אלול"} | ||
if | if is_leap(year) then | ||
months = {"תשרי", "חשון", "כסלו", "טבת", "שבט", "אדר א'", "אדר ב'", "ניסן", "אייר", "סיון", "תמוז", "אב", "אלול"} | months = {"תשרי", "חשון", "כסלו", "טבת", "שבט", "אדר א'", "אדר ב'", "ניסן", "אייר", "סיון", "תמוז", "אב", "אלול"} | ||
end | end | ||
שורה 86: | שורה 86: | ||
end | end | ||
function | local function return_day(year, month, day, previous) | ||
-- מקבלת שנה עברית בתור מספר וחודש בתור מחרוזת ויום בחודש בתור מספר ומחזירה את היום הקודם (ברירת מחדל) או הבא | -- מקבלת שנה עברית בתור מספר וחודש בתור מחרוזת ויום בחודש בתור מספר ומחזירה את היום הקודם (ברירת מחדל) או הבא | ||
if previous then | if previous then | ||
if day == 1 then return | if day == 1 then return days_a_month(year, return_month(year, month, true)) else return day - 1 end | ||
else if day == | else if day == days_a_month(year, month) then return 1 else return day + 1 end | ||
end | end | ||
return error("שגיאת תאריך") | return error("שגיאת תאריך") | ||
end | end | ||
function p.next_month( | function p.next_month(frame) | ||
-- מקבלת שנה עברית בתור מספר וחודש בתור מחרוזת ומחזירה טבלה עם החודש הבא | -- מקבלת שנה עברית בתור מספר וחודש בתור מחרוזת ומחזירה טבלה עם החודש הבא | ||
month = | local year = frame.args["year"] | ||
local month = frame.args["month"] | |||
month = return_month(year, month, false) | |||
if month == "תשרי" then year = year + 1 end | if month == "תשרי" then year = year + 1 end | ||
return {year, month} | return {year, month} | ||
end | end | ||
function p.previous_month( | function p.previous_month(frame) | ||
-- מקבלת שנה עברית בתור מספר וחודש בתור מחרוזת ומחזירה טבלה עם החודש הקודם | -- מקבלת שנה עברית בתור מספר וחודש בתור מחרוזת ומחזירה טבלה עם החודש הקודם | ||
month = | local year = frame.args["year"] | ||
local month = frame.args["month"] | |||
month = return_month(year, month, true) | |||
if month == "אלול" then year = year - 1 end | if month == "אלול" then year = year - 1 end | ||
return {year, month} | return {year, month} | ||
end | end | ||
function p.next_date( | function p.next_date(frame) | ||
-- מקבלת תאריך מלא ומחזירה טבלה עם התאריך המלא הבא | -- מקבלת תאריך מלא ומחזירה טבלה עם התאריך המלא הבא | ||
day = | local year = frame.args["year"] | ||
local month = frame.args["month"] | |||
local day = frame.args["day"] | |||
day = return_day(year, month, day, false) | |||
if day == 1 then | if day == 1 then | ||
month = | month = return_month(year, month, false) | ||
if month == "תשרי" then year = year + 1 end | if month == "תשרי" then year = year + 1 end | ||
end | end | ||
שורה 119: | שורה 126: | ||
end | end | ||
function p.previous_date( | function p.previous_date(frame) | ||
-- מקבלת תאריך מלא ומחזירה טבלה עם התאריך המלא הקודם | -- מקבלת תאריך מלא ומחזירה טבלה עם התאריך המלא הקודם | ||
new_day = | local year = frame.args["year"] | ||
local month = frame.args["month"] | |||
local day = frame.args["day"] | |||
new_day = return_day(year, month, day, true) | |||
if day == 1 then | if day == 1 then | ||
if month == "תשרי" then year = year - 1 end | if month == "תשרי" then year = year - 1 end | ||
month = | month = return_month(year, month, true) | ||
end | end | ||
return {year, month, new_day} | return {year, month, new_day} |