File: israel.py

package info (click to toggle)
python-holidays 0.90-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 59,088 kB
  • sloc: python: 121,956; javascript: 85; makefile: 62
file content (152 lines) | stat: -rw-r--r-- 5,102 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#  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 CONTRIBUTORS 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 gettext import gettext as tr

from holidays.calendars.gregorian import _timedelta, FRI, SAT
from holidays.constants import OPTIONAL, PUBLIC, SCHOOL
from holidays.groups import HebrewCalendarHolidays
from holidays.observed_holiday_base import (
    ObservedHolidayBase,
    MON_TO_NEXT_TUE,
    THU_TO_PREV_WED,
    FRI_TO_PREV_WED,
    FRI_TO_PREV_THU,
    SAT_TO_PREV_THU,
    SAT_TO_NEXT_SUN,
    SUN_TO_NEXT_MON,
)


class Israel(ObservedHolidayBase, HebrewCalendarHolidays):
    """Israel holidays.

    References:
        * <https://en.wikipedia.org/wiki/Public_holidays_in_Israel>
        * <https://web.archive.org/web/20190923042619/https://www.knesset.gov.il/laws/special/heb/jerusalem_day_law.htm>
    """

    country = "IL"
    default_language = "he"
    # %s (observed).
    observed_label = tr("%s (נצפה)")
    supported_categories = (OPTIONAL, PUBLIC, SCHOOL)
    supported_languages = ("en_US", "he", "th", "uk")
    weekend = {FRI, SAT}
    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 _add_observed(self, dt, name, rule):
        is_observed, _ = super()._add_observed(dt, name, rule=rule)
        if not is_observed:
            self._add_holiday(name, dt)

    def _populate_public_holidays(self):
        # Rosh Hashanah (New Year).
        self._add_rosh_hashanah(tr("ראש השנה"), range(2))

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

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

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

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

        # Shavuot.
        self._add_shavuot(tr("שבועות"))

    def _populate_optional_holidays(self):
        # Chol HaMoed Sukkot (Feast of Tabernacles holiday).
        self._add_sukkot(tr("חול המועד סוכות"), range(1, 6))

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

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

        # Chol HaMoed Pesach (Passover holiday).
        self._add_passover(tr("חול המועד פסח"), range(1, 6))

        if self._year >= 1963:
            rule = THU_TO_PREV_WED + FRI_TO_PREV_WED
            if self._year >= 2004:
                rule += SUN_TO_NEXT_MON
            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_lag_baomer(tr("יום ירושלים"), +10)

        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):
        # 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_purim(tr("פורים"))

        # Chol HaMoed Pesach (Passover holiday).
        self._add_passover(tr("חול המועד פסח"), range(1, 6))

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


class IL(Israel):
    pass


class ISR(Israel):
    pass