Skip to content

Commit

Permalink
Add HebrewCalendarHolidays to holidays groups, refactor Israel holi…
Browse files Browse the repository at this point in the history
…days (#2186)
  • Loading branch information
KJhellico authored Dec 24, 2024
1 parent 43f3f2c commit e92a949
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 83 deletions.
35 changes: 32 additions & 3 deletions holidays/calendars/hebrew.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,36 @@ class _HebrewLunisolar:
2100: (OCT, 13),
}

@staticmethod
def _get_holiday(holiday: str, year: int) -> Optional[date]:
dt = getattr(_HebrewLunisolar, f"{holiday}_DATES", {}).get(year, ())
def _get_holiday(self, holiday: str, year: int) -> Optional[date]:
dt = getattr(self, f"{holiday}_DATES", {}).get(year, ())
return date(year, *dt) if dt else None

def hanukkah_date(self, year: int) -> set[Optional[date]]:
return {self._get_holiday(HANUKKAH, y) for y in (year - 1, year)}

def israel_independence_date(self, year: int) -> Optional[date]:
return self._get_holiday(INDEPENDENCE_DAY, year)

def lag_baomer_date(self, year: int) -> Optional[date]:
return self._get_holiday(LAG_BAOMER, year)

def passover_date(self, year: int) -> Optional[date]:
return self._get_holiday(PASSOVER, year)

def purim_date(self, year: int) -> Optional[date]:
return self._get_holiday(PURIM, year)

def rosh_hashanah_date(self, year: int) -> Optional[date]:
return self._get_holiday(ROSH_HASHANAH, year)

def shavuot_date(self, year: int) -> Optional[date]:
return self._get_holiday(SHAVUOT, year)

def sukkot_date(self, year: int) -> Optional[date]:
return self._get_holiday(SUKKOT, year)

def tisha_bav_date(self, year: int) -> Optional[date]:
return self._get_holiday(TISHA_BAV, year)

def yom_kippur_date(self, year: int) -> Optional[date]:
return self._get_holiday(YOM_KIPPUR, year)
135 changes: 55 additions & 80 deletions holidays/countries/israel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,9 @@

from gettext import gettext as tr

from holidays.calendars import _HebrewLunisolar
from holidays.calendars.gregorian import _timedelta, FRI, SAT
from holidays.calendars.hebrew import (
HANUKKAH,
INDEPENDENCE_DAY,
LAG_BAOMER,
PASSOVER,
PURIM,
ROSH_HASHANAH,
SHAVUOT,
SUKKOT,
YOM_KIPPUR,
)
from holidays.constants import OPTIONAL, PUBLIC, SCHOOL
from holidays.groups import HebrewCalendarHolidays
from holidays.observed_holiday_base import (
ObservedHolidayBase,
MON_TO_NEXT_TUE,
Expand All @@ -38,7 +27,7 @@
)


class Israel(ObservedHolidayBase):
class Israel(ObservedHolidayBase, HebrewCalendarHolidays):
"""
Israel holidays.
Expand All @@ -57,117 +46,103 @@ class Israel(ObservedHolidayBase):
start_year = 1948

def __init__(self, *args, **kwargs):
HebrewCalendarHolidays.__init__(self)
kwargs.setdefault("observed_rule", FRI_TO_PREV_THU + SAT_TO_PREV_THU)
super().__init__(*args, **kwargs)

def _get_holiday(self, holiday: str):
return _HebrewLunisolar._get_holiday(holiday, self._year)
def _add_observed(self, dt, name, rule):
is_observed, _ = super()._add_observed(dt, name, rule)
if not is_observed:
self._add_holiday(name, dt)

def _populate_public_holidays(self):
# Rosh Hashanah (New Year).
name = tr("ראש השנה")
rosh_hashanah_dt = self._get_holiday(ROSH_HASHANAH)
self._add_holiday(name, rosh_hashanah_dt)
self._add_holiday(name, _timedelta(rosh_hashanah_dt, +1))
self._add_rosh_hashanah(tr("ראש השנה"), range(2))

# Yom Kippur (Day of Atonement).
self._add_holiday(tr("יום כיפור"), self._get_holiday(YOM_KIPPUR))
self._add_yom_kippur(tr("יום כיפור"))

sukkot_dt = self._get_holiday(SUKKOT)
# Sukkot (Feast of Tabernacles).
self._add_holiday(tr("סוכות"), sukkot_dt)
self._add_sukkot(tr("סוכות"))
# Simchat Torah / Shemini Atzeret.
self._add_holiday(tr("שמחת תורה/שמיני עצרת"), _timedelta(sukkot_dt, +7))
self._add_sukkot(tr("שמחת תורה/שמיני עצרת"), +7)

passover_dt = self._get_holiday(PASSOVER)
# Pesach (Passover).
self._add_holiday(tr("פסח"), passover_dt)
self._add_passover(tr("פסח"))
# Shvi'i shel Pesach (Seventh day of Passover)
self._add_holiday(tr("שביעי של פסח"), _timedelta(passover_dt, +6))
self._add_passover(tr("שביעי של פסח"), +6)

# Yom Ha-Atzmaut (Independence Day).
name = tr("יום העצמאות")
independence_day_dt = self._get_holiday(INDEPENDENCE_DAY)
rule = FRI_TO_PREV_THU + SAT_TO_PREV_THU
if self._year >= 2004:
rule += MON_TO_NEXT_TUE
is_observed, _ = self._add_observed(independence_day_dt, name, rule)
if not is_observed:
self._add_holiday(name, independence_day_dt)
self._add_observed(
self._hebrew_calendar.israel_independence_date(self._year),
# Yom Ha-Atzmaut (Independence Day).
tr("יום העצמאות"),
rule,
)

# Shavuot.
self._add_holiday(tr("שבועות"), self._get_holiday(SHAVUOT))
self._add_shavuot(tr("שבועות"))

def _populate_optional_holidays(self):
sukkot_dt = self._get_holiday(SUKKOT)
for offset in range(1, 6):
# Chol HaMoed Sukkot (Feast of Tabernacles holiday).
self._add_holiday(tr("חול המועד סוכות"), _timedelta(sukkot_dt, offset))
# Chol HaMoed Sukkot (Feast of Tabernacles holiday).
self._add_sukkot(tr("חול המועד סוכות"), range(1, 6))

if self._year >= 2008:
# Sigd.
self._add_holiday(tr("סיגד"), _timedelta(self._get_holiday(YOM_KIPPUR), +49))
self._add_yom_kippur(tr("סיגד"), +49)

# Purim.
self._add_holiday(tr("פורים"), self._get_holiday(PURIM))
self._add_purim(tr("פורים"))

passover_dt = self._get_holiday(PASSOVER)
for offset in range(1, 6):
# Chol HaMoed Pesach (Passover holiday).
self._add_holiday(tr("חול המועד פסח"), _timedelta(passover_dt, offset))
# Chol HaMoed Pesach (Passover holiday).
self._add_passover(tr("חול המועד פסח"), range(1, 6))

if self._year >= 1963:
# Yom Hazikaron (Fallen Soldiers and Victims of Terrorism Remembrance Day).
name = tr("יום הזיכרון לחללי מערכות ישראל ונפגעי פעולות האיבה")
remembrance_day_dt = _timedelta(self._get_holiday(INDEPENDENCE_DAY), -1)
rule = THU_TO_PREV_WED + FRI_TO_PREV_WED
if self._year >= 2004:
rule += SUN_TO_NEXT_MON
is_observed, _ = self._add_observed(remembrance_day_dt, name, rule)
if not is_observed:
self._add_holiday(name, remembrance_day_dt)
self._add_observed(
_timedelta(self._hebrew_calendar.israel_independence_date(self._year), -1),
# Yom Hazikaron (Fallen Soldiers and Victims of Terrorism Remembrance Day).
tr("יום הזיכרון לחללי מערכות ישראל ונפגעי פעולות האיבה"),
rule,
)

if self._year >= 1998:
# Yom Yerushalayim (Jerusalem Day).
self._add_holiday(tr("יום ירושלים"), _timedelta(self._get_holiday(LAG_BAOMER), +10))
self._add_lag_baomer(tr("יום ירושלים"), +10)

# Tisha B'Av (Tisha B'Av, fast).
name = tr("תשעה באב")
tisha_bav_dt = self._get_holiday("TISHA_BAV")
is_observed, _ = self._add_observed(tisha_bav_dt, name, SAT_TO_NEXT_SUN)
if not is_observed:
self._add_holiday(name, tisha_bav_dt)
self._add_observed(
self._hebrew_calendar.tisha_bav_date(self._year),
# Tisha B'Av (Tisha B'Av, fast).
tr("תשעה באב"),
SAT_TO_NEXT_SUN,
)

def _populate_school_holidays(self):
sukkot_dt = self._get_holiday(SUKKOT)
for offset in range(1, 6):
# Chol HaMoed Sukkot (Feast of Tabernacles holiday).
self._add_holiday(tr("חול המועד סוכות"), _timedelta(sukkot_dt, offset))

for year in (self._year - 1, self._year):
hanukkah_dt = _HebrewLunisolar._get_holiday(HANUKKAH, year)
for offset in range(8):
# Hanukkah.
self._add_holiday(tr("חנוכה"), _timedelta(hanukkah_dt, offset))

# Ta`anit Ester (Fast of Esther).
name = tr("תענית אסתר")
purim_dt = self._get_holiday(PURIM)
taanit_ester_dt = _timedelta(purim_dt, -1)
is_observed, _ = self._add_observed(taanit_ester_dt, name, SAT_TO_PREV_THU)
if not is_observed:
self._add_holiday(name, taanit_ester_dt)
# Chol HaMoed Sukkot (Feast of Tabernacles holiday).
self._add_sukkot(tr("חול המועד סוכות"), range(1, 6))

# Hanukkah.
self._add_hanukkah(tr("חנוכה"), range(8))

self._add_observed(
_timedelta(self._hebrew_calendar.purim_date(self._year), -1),
# Ta`anit Ester (Fast of Esther).
tr("תענית אסתר"),
SAT_TO_PREV_THU,
)

# Purim.
self._add_holiday(tr("פורים"), purim_dt)
self._add_purim(tr("פורים"))

passover_dt = self._get_holiday(PASSOVER)
for offset in range(1, 6):
# Chol HaMoed Pesach (Passover holiday).
self._add_holiday(tr("חול המועד פסח"), _timedelta(passover_dt, offset))
# Chol HaMoed Pesach (Passover holiday).
self._add_passover(tr("חול המועד פסח"), range(1, 6))

# Lag Ba'omer (Lag BaOmer).
self._add_holiday(tr('ל"ג בעומר'), self._get_holiday(LAG_BAOMER))
self._add_lag_baomer(tr('ל"ג בעומר'))


class IL(Israel):
Expand Down
1 change: 1 addition & 0 deletions holidays/groups/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from holidays.groups.christian import ChristianHolidays
from holidays.groups.custom import StaticHolidays
from holidays.groups.eastern import EasternCalendarHolidays
from holidays.groups.hebrew import HebrewCalendarHolidays
from holidays.groups.hindu import HinduCalendarHolidays
from holidays.groups.international import InternationalHolidays
from holidays.groups.islamic import IslamicHolidays
Expand Down
Loading

0 comments on commit e92a949

Please sign in to comment.