Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HebrewCalendarHolidays to holidays groups, refactor Israel holidays #2186

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 39 additions & 76 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 @@ -60,114 +49,88 @@ def __init__(self, *args, **kwargs):
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_hebrew_holiday(tr("ראש השנה"), self._rosh_hashanah_date, range(2))

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

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

passover_dt = self._get_holiday(PASSOVER)
# Pesach (Passover).
self._add_holiday(tr("פסח"), passover_dt)
self._add_hebrew_holiday(tr("פסח"), self._passover_date)
# Shvi'i shel Pesach (Seventh day of Passover)
self._add_holiday(tr("שביעי של פסח"), _timedelta(passover_dt, +6))
self._add_hebrew_holiday(tr("שביעי של פסח"), self._passover_date, +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)
# Yom Ha-Atzmaut (Independence Day).
self._add_observed(self._israel_independence_date, tr("יום העצמאות"), rule)

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

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_hebrew_holiday(tr("חול המועד סוכות"), self._sukkot_date, range(1, 6))

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

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

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_hebrew_holiday(tr("חול המועד פסח"), self._passover_date, 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._israel_independence_date, -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_hebrew_holiday(tr("יום ירושלים"), self._lag_baomer_date, +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._tisha_bav_date, 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))
# Chol HaMoed Sukkot (Feast of Tabernacles holiday).
self._add_hebrew_holiday(tr("חול המועד סוכות"), self._sukkot_date, range(1, 6))

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))
for hanukkah_dt in self._hanukkah_date:
# Hanukkah.
self._add_hebrew_holiday(tr("חנוכה"), hanukkah_dt, range(8))

# 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)
self._add_observed(_timedelta(self._purim_date, -1), tr("תענית אסתר"), SAT_TO_PREV_THU)

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

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_hebrew_holiday(tr("חול המועד פסח"), self._passover_date, range(1, 6))

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


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
156 changes: 156 additions & 0 deletions holidays/groups/hebrew.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# holidays
# --------
# A fast, efficient Python library for generating country, province and state
# specific sets of holidays on the fly. It aims to make determining whether a
# specific date is a holiday as fast and flexible as possible.
#
# Authors: Vacanza Team and individual contributors (see AUTHORS file)
# dr-prodigy <dr.prodigy.github@gmail.com> (c) 2017-2023
# ryanss <ryanssdev@icloud.com> (c) 2014-2017
# Website: https://github.com/vacanza/holidays
# License: MIT (see LICENSE file)

from collections.abc import Iterable
from datetime import date
from typing import Optional, Union

from holidays.calendars import _HebrewLunisolar
from holidays.calendars.gregorian import _timedelta
from holidays.calendars.hebrew import (
HANUKKAH,
INDEPENDENCE_DAY,
LAG_BAOMER,
PASSOVER,
PURIM,
ROSH_HASHANAH,
SHAVUOT,
SUKKOT,
TISHA_BAV,
YOM_KIPPUR,
)


class HebrewCalendarHolidays:
"""
Hebrew lunisolar calendar holidays.
"""

@property
def _hanukkah_date(self) -> set[Optional[date]]:
"""
Return Hanukkah date.
In some Gregorian years, there may be two Hanukkah dates.

Hanukkah is a Jewish festival commemorating the recovery of Jerusalem
and subsequent rededication of the Second Temple.
https://en.wikipedia.org/wiki/Hanukkah
"""
return {
_HebrewLunisolar._get_holiday(HANUKKAH, year) for year in (self._year - 1, self._year)
}

@property
def _israel_independence_date(self) -> Optional[date]:
"""
Return Israel Independence Day date.

Yom Ha'atzmaut is Israel's national day, commemorating the Israeli Declaration
of Independence on 14 May 1948.
https://en.wikipedia.org/wiki/Independence_Day_(Israel)
"""
return _HebrewLunisolar._get_holiday(INDEPENDENCE_DAY, self._year)

@property
def _lag_baomer_date(self) -> Optional[date]:
"""
Return Lag BaOmer date.

Lag BaOmer, also Lag B'Omer or Lag LaOmer, is a Jewish religious holiday celebrated
on the 33rd day of the Counting of the Omer, which occurs on the 18th day of
the Hebrew month of Iyar.
https://en.wikipedia.org/wiki/Lag_BaOmer
"""
return _HebrewLunisolar._get_holiday(LAG_BAOMER, self._year)

@property
def _passover_date(self) -> Optional[date]:
"""
Return Passover date.

Passover, also called Pesach, is a major Jewish holiday and one of the Three Pilgrimage
Festivals. It celebrates the Exodus of the Israelites from slavery in Egypt.
https://en.wikipedia.org/wiki/Passover
"""
return _HebrewLunisolar._get_holiday(PASSOVER, self._year)

@property
def _purim_date(self) -> Optional[date]:
"""
Return Purim date.

Purim is a Jewish holiday that commemorates the saving of the Jewish people
from annihilation at the hands of an official of the Achaemenid Empire named Haman,
as it is recounted in the Book of Esther.
https://en.wikipedia.org/wiki/Purim
"""
return _HebrewLunisolar._get_holiday(PURIM, self._year)

@property
def _rosh_hashanah_date(self) -> Optional[date]:
"""
Return Rosh Hashanah date.

Rosh Hashanah is the New Year in Judaism.
https://en.wikipedia.org/wiki/Rosh_Hashanah
"""
return _HebrewLunisolar._get_holiday(ROSH_HASHANAH, self._year)

@property
def _shavuot_date(self) -> Optional[date]:
"""
Return Shavuot date.

Shavuot, or Shvues, is a Jewish holiday, one of the biblically ordained
Three Pilgrimage Festivals. It occurs on the sixth day of the Hebrew month of Sivan.
https://en.wikipedia.org/wiki/Shavuot
"""
return _HebrewLunisolar._get_holiday(SHAVUOT, self._year)

@property
def _sukkot_date(self) -> Optional[date]:
"""
Return Sukkot date.

Sukkot, also known as the Feast of Tabernacles or Feast of Booths, is a Torah-commanded
holiday celebrated for seven days, beginning on the 15th day of the month of Tishrei.
https://en.wikipedia.org/wiki/Sukkot
"""
return _HebrewLunisolar._get_holiday(SUKKOT, self._year)

@property
def _tisha_bav_date(self) -> Optional[date]:
"""
Return Tisha B'Av date.

Tisha B'Av is an annual fast day in Judaism.
https://en.wikipedia.org/wiki/Tisha_B%27Av
"""
return _HebrewLunisolar._get_holiday(TISHA_BAV, self._year)

@property
def _yom_kippur_date(self) -> Optional[date]:
"""
Return Yom Kippur date.

Yom Kippur (Day of Atonement) is the holiest day of the year in Judaism.
It occurs annually on the 10th of Tishrei.
https://en.wikipedia.org/wiki/Yom_Kippur
"""
return _HebrewLunisolar._get_holiday(YOM_KIPPUR, self._year)

def _add_hebrew_holiday(self, name: str, dt: date, days_delta: Union[int, Iterable[int]] = 0):
if days_delta:
for delta in (days_delta,) if isinstance(days_delta, int) else days_delta:
self._add_holiday(name, _timedelta(dt, delta))
else:
self._add_holiday(name, dt)
Loading