Exemple #1
0
def _gentable(year, israel=False):
    """Return OrderedDict mapping date of Shabbos to list of parsha numbers.

    The numbers start with Beraishis as 0. Double parshios are represented
    as a list of the two numbers. If there is no Parsha the value is None.
    """
    parshalist = deque([51, 52] + list(range(52)))
    table = OrderedDict()
    leap = HebrewDate._is_leap(year)
    pesachday = HebrewDate(year, 1, 15).weekday()
    rosh_hashana = HebrewDate(year, 7, 1)
    shabbos = (rosh_hashana + 2).shabbos()
    if rosh_hashana.weekday() > 4:
        parshalist.popleft()

    while shabbos.year == year:
        if _parshaless(shabbos, israel):
            table[shabbos] = None
        else:
            parsha = parshalist.popleft()
            table[shabbos] = [parsha,]
            if(
               (parsha == 21 and (HebrewDate(year, 1, 14)-shabbos) // 7 < 3) or
               (parsha in [26, 28] and not leap) or
               (parsha == 31 and not leap and (
                                               not israel or pesachday != 7
                                               )) or
               (parsha == 38 and not israel and pesachday == 5) or
               (parsha == 41 and (HebrewDate(year, 5, 9)-shabbos) // 7 < 2)  or
               (parsha == 50 and HebrewDate(year+1, 7, 1).weekday() > 4)
               ):  #  If any of that then it's a double parsha.
                table[shabbos].append(parshalist.popleft())
        shabbos += 7
    return table
Exemple #2
0
    def __init__(self, year):

        """
        The initializer for a Year object.
        """
        if year < 1:
            raise ValueError('Year {0} is before creation.'.format(year))
        self.year = year
        self.leap = HebrewDate._is_leap(year)
Exemple #3
0
 def __init__(self, year, month):
     if year < 1:
         raise ValueError('Year is before creation.')
     self.year = year
     leap = HebrewDate._is_leap(self.year)
     yearlength = 13 if leap else 12
     if month < 1 or month > yearlength:
         raise ValueError('''Month must be between 1 and 12 for a normal
         year and 13 for a leap year.''')
     self.month = month
     self._monthnames[12] = 'Adar Rishon' if leap else 'Adar'
     self.name = self._monthnames[self.month]
Exemple #4
0
    def get_variable_days(self, year):
        days = super().get_variable_days(year)

        hebrew_date = GregorianDate(year=year, month=1, day=1).to_heb()
        jewish_year = hebrew_date.year

        holidays_hebrew_dates = [
            (HebrewDate(jewish_year, 6, 29), "Rosh Hashana Eve"),
            (HebrewDate(jewish_year + 1, 7, 1), "Rosh Hashana"),
            (HebrewDate(jewish_year + 1, 7, 2), "Rosh Hashana"),
            (HebrewDate(jewish_year + 1, 7, 9), "Yom Kippur Eve"),
            (HebrewDate(jewish_year + 1, 7, 10), "Yom Kippur"),
            (HebrewDate(jewish_year + 1, 7, 14), "Sukkot Eve"),
            (HebrewDate(jewish_year + 1, 7, 15), "Sukkot"),
            (HebrewDate(jewish_year + 1, 7, 21), "Shmini Atzeres Eve"),
            (HebrewDate(jewish_year + 1, 7, 22), "Shmini Atzeres"),
            (HebrewDate(jewish_year, 1, 14), "Pesach Eve"),
            (HebrewDate(jewish_year, 1, 15), "Pesach"),
            (HebrewDate(jewish_year, 1, 20), "7th of Pesach Eve"),
            (HebrewDate(jewish_year, 1, 21), "7th of Pesach"),
            (HebrewDate(jewish_year, 3, 5), "Shavout Eve"),
            (HebrewDate(jewish_year, 3, 6), "Shavout"),
        ]
        holidays_hebrew_dates += self.get_hebrew_independence_day(jewish_year)

        for holiday_hebrew_date, holiday_name in holidays_hebrew_dates:
            days.append((holiday_hebrew_date.to_pydate(), holiday_name))
        return days
def festival(date, israel=False):
    """Return Jewish festival of given day.

    This method will return all major and minor religous
    Jewish holidays not including fast days.

    Parameters
    ----------
    date : ``HebrewDate``, ``GregorianDate``, or ``JulianDay``
      Any date that implements a ``to_heb()`` method which returns a
      ``HebrewDate`` can be used.

    israel : bool, optional
      ``True`` if you want the holidays according to the Israel
      schedule. Defaults to ``False``.

    Returns
    -------
    str or ``None``
      The name of the festival or ``None`` if the given date is not
      a Jewish festival.
    """
    date = date.to_heb()
    year = date.year
    month = date.month
    day = date.day
    if month == 7:
        if day in [1, 2]:
            return 'Rosh Hashana'
        elif day == 10:
            return 'Yom Kippur'
        elif day in range(15, 22):
            return 'Succos'
        elif day == 22:
            return 'Shmini Atzeres'
        elif day == 23 and israel == False:
            return 'Simchas Torah'
    elif ((month == 9 and day in range(25, 30))
          or date in [(HebrewDate(year, 9, 29) + n) for n in range(1, 4)]):
        return 'Chanuka'
    elif month == 11 and day == 15:
        return "Tu B'shvat"
    elif month == 12:
        leap = HebrewDate._is_leap(year)
        if day == 14:
            return 'Purim Katan' if leap else 'Purim'
        if day == 15 and not leap:
            return 'Shushan Purim'
    elif month == 13:
        if day == 14:
            return 'Purim'
        elif day == 15:
            return 'Shushan Purim'
    elif month == 1 and day in range(15, 22 if israel else 23):
        return 'Pesach'
    elif month == 2 and day == 14:
        return 'Pesach Sheni'
    elif month == 2 and day == 18:
        return "Lag Ba'omer"
    elif month == 3 and (day == 6 if israel else day in (6, 7)):
        return 'Shavuos'
    elif month == 5 and day == 15:
        return "Tu B'av"
Exemple #6
0
def test_from_pydate():
    date = datetime.date(2018, 8, 27)
    assert date == GregorianDate.from_pydate(date).to_jd().to_pydate()
    assert date == HebrewDate.from_pydate(date).to_pydate()
    assert date == JulianDay.from_pydate(date).to_pydate()
Exemple #7
0
def test_to_pydate():
    day = HebrewDate(5778, 6, 1)
    jd = day.to_jd()
    for day_type in [day, jd]:
        assert day_type.to_pydate() == datetime.date(2018, 8, 12)
Exemple #8
0
 def __len__(self):
     return HebrewDate._days_in_year(self.year)
Exemple #9
0
 def __len__(self):
     return HebrewDate._month_length(self.year, self.month)
Exemple #10
0
 def __init__(self, year):
     if year < 1:
         raise ValueError('Year {0} is before creation.'.format(year))
     self.year = year
     self.leap = HebrewDate._is_leap(year)
Exemple #11
0
def test_from_pydate():
    date = datetime.date(2018, 8, 27)
    assert date == GregorianDate.from_pydate(date).to_jd().to_pydate()
    assert date == HebrewDate.from_pydate(date).to_pydate()
    assert date == JulianDay.from_pydate(date).to_pydate()
Exemple #12
0
def test_to_pydate():
    day = HebrewDate(5778, 6, 1)
    jd = day.to_jd()
    for day_type in [day, jd]:
        assert day_type.to_pydate() == datetime.date(2018, 8, 12)
Exemple #13
0
def test_is_leap():
    assert GregorianDate(2020, 10, 26).is_leap() == True
    assert GregorianDate(2021, 10, 26).is_leap() == False
    assert HebrewDate(5781, 10, 26).is_leap() == False
    assert HebrewDate(5782, 10, 26).is_leap() == True
Exemple #14
0
def holiday(date, israel=False):
    """Return Jewish holiday of given date.

    The holidays include the major and minor religious Jewish
    holidays including fast days.

    Parameters
    ----------
    date : ``HebrewDate``, ``GregorianDate``, or ``JulianDay``
      Any date that implements a ``to_heb()`` method which returns a
      ``HebrewDate`` can be used.

    israel : boolian, optional
      ``True`` if you want the holidays according to the israel
      schedule. Defaults to ``False``.

    Returns
    -------
    str or ``None``
      The name of the holiday or ``None`` if the given date is not
      a Jewish holiday.
    """
    date = date.to_heb()
    year = date.year
    month = date.month
    day = date.day
    table = _fast_day_table(year)
    if date in table:
        return table[date]
    if month == 7:
        if day in range(1, 3):
            return 'Rosh Hashana'
        elif day == 10:
            return 'Yom Kippur'
        elif day in range(15, 22):
            return 'Succos'
        elif day == 22:
            return 'Shmini Atzeres'
        elif day == 23 and israel == False:
            return 'Simchas Torah'
    elif(
         (month == 9 and day in range(25, 30)) or
         date in [(HebrewDate(year, 9, 29) + n) for n in range(1, 4)]
         ):
        return 'Chanuka'
    elif month == 11 and day == 15:
        return "Tu B'shvat"
    elif month == 12:
        leap = HebrewDate._is_leap(year)
        if day == 14:
            return 'Purim Katan' if leap else 'Purim'
        if day == 15 and not leap:
            return 'Shushan Purim'
    elif month == 13:
        if day == 14:
                return 'Purim'
        elif day == 15:
            return 'Shushan Purim'
    elif month == 1 and day in range(15, 22 if israel else 23):
        return 'Pesach'
    elif month == 2 and day == 18:
        return "Lag Ba'omer"
    elif month == 3 and (day == 6 if israel else day in (6, 7)):
        return 'Shavuos'
    elif month == 5 and day == 15:
        return "Tu B'av"
Exemple #15
0
 def __len__(self):
     return HebrewDate._month_length(self.year, self.month)
Exemple #16
0
def get_holidays(date=datetime.date.today(), diaspora=False):
    hebYear, hebMonth, hebDay = GregorianDate(date.year, date.month,
                                              date.day).to_heb().tuple()

    # Holidays in Nisan
    if hebDay == 15 and hebMonth == 1:
        return {0: 'Pesach', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 16 and hebMonth == 1:
        return {0: 'Pesach', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 17 and hebMonth == 1:
        return {0: 'Pesach', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 18 and hebMonth == 1:
        return {0: 'Pesach', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 19 and hebMonth == 1:
        return {0: 'Pesach', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 20 and hebMonth == 1:
        return {0: 'Pesach', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 21 and hebMonth == 1:
        return {0: 'Pesach', 3: 'Hag', 4: 'Shabbat'}
    # if hebDay == 22 and hebMonth == 1 and diaspora:
    #    return {0: 'Pesach'})

    # Yom Hashoah
    if HebrewDate(hebYear, 1,
                  27).weekday() == 6 and hebDay == 26 and hebMonth == 1:
        return {0: 'YomHashoah'}
    elif hebYear >= 5757 and HebrewDate(
            hebYear, 1, 27).weekday() == 1 and hebDay == 28 and hebMonth == 1:
        return {0: 'YomHashoah'}
    elif hebDay == 27 and hebMonth == 1:
        return {0: 'YomHashoah'}

    # Holidays in Iyar

    # Yom Hazikaron
    if HebrewDate(hebYear, 2, 4).weekday(
    ) == 6 and hebDay == 2 and hebMonth == 2:  # If 4th of Iyar is a Thursday then Yom Hazikaron is on 2th of Iyar
        return {2: 'YomHazikaron'}
    elif HebrewDate(hebYear, 2,
                    4).weekday() == 5 and hebDay == 3 and hebMonth == 2:
        return {2: 'YomHazikaron'}
    elif hebYear >= 5764 and HebrewDate(
            hebYear, 2, 4).weekday() == 1 and hebDay == 5 and hebMonth == 2:
        return {2: 'YomHazikaron'}
    elif hebDay == 4 and hebMonth == 2:
        return {2: 'YomHazikaron'}

    # Yom Ha'Azmaut
    if HebrewDate(hebYear, 2,
                  5).weekday() == 7 and hebDay == 3 and hebMonth == 2:
        return {1: 'YomHaatzmaut', 3: 'Hag', 4: 'Shabbat'}
    elif HebrewDate(hebYear, 2,
                    5).weekday() == 6 and hebDay == 4 and hebMonth == 2:
        return {1: 'YomHaatzmaut', 3: 'Hag', 4: 'Shabbat'}
    elif hebYear >= 5764 and HebrewDate(
            hebYear, 2, 4).weekday() == 1 and hebDay == 6 and hebMonth == 2:
        return {1: 'YomHaatzmaut', 3: 'Hag', 4: 'Shabbat'}
    elif hebDay == 5 and hebMonth == 2:
        return {1: 'YomHaatzmaut', 3: 'Hag', 4: 'Shabbat'}

    if hebDay == 18 and hebMonth == 2:
        return {0: 'LagBaomer'}
    if hebDay == 28 and hebMonth == 2:
        return {0: 'YomYerushalayim'}

    # Holidays in Sivan
    if hebDay == 6 and hebMonth == 3:
        return {0: 'Shavuot', 3: 'Hag', 4: 'Shabbat'}

    # Holidays in Av
    if HebrewDate(hebYear, 5,
                  9).weekday() == 7 and hebDay == 10 and hebMonth == 5:
        return {0: 'TishaBAv'}
    elif hebDay == 9 and hebMonth == 5:
        return {0: 'TishaBAv'}

    if hebDay == 15 and hebMonth == 5:
        return {0: 'TuBAv'}

    # Holidays in Tishrei
    if hebDay == 1 and hebMonth == 7:
        return {0: 'RoshHashana', 1: 'ShabbatShuva', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 2 and hebMonth == 7:
        return {0: 'RoshHashana', 1: 'ShabbatShuva', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 3 and hebMonth == 7:
        return {1: 'ShabbatShuva'}
    if hebDay == 4 and hebMonth == 7:
        return {1: 'ShabbatShuva'}
    if hebDay == 5 and hebMonth == 7:
        return {1: 'ShabbatShuva'}
    if hebDay == 6 and hebMonth == 7:
        return {1: 'ShabbatShuva'}
    if hebDay == 7 and hebMonth == 7:
        return {1: 'ShabbatShuva'}
    if hebDay == 8 and hebMonth == 7:
        return {1: 'ShabbatShuva'}
    if hebDay == 9 and hebMonth == 7:
        return {1: 'ShabbatShuva'}
    if hebDay == 10 and hebMonth == 7:
        return {1: 'YomKippur', 2: 'ShabbatShuva', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 15 and hebMonth == 7:
        return {1: 'Sukkot', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 16 and hebMonth == 7:
        return {1: 'Sukkot', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 17 and hebMonth == 7:
        return {1: 'Sukkot', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 18 and hebMonth == 7:
        return {1: 'Sukkot', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 19 and hebMonth == 7:
        return {1: 'Sukkot', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 20 and hebMonth == 7:
        return {1: 'Sukkot', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 21 and hebMonth == 7:
        return {1: 'Sukkot', 3: 'Hag', 4: 'Shabbat'}
    if hebDay == 22 and hebMonth == 7:
        return {1: 'SimchatTorah', 3: 'Hag', 4: 'Shabbat'}

    # Holidays in Kislev
    if hebDay == 25 and hebMonth == 9:
        return {0: 'Hanukka'}
    if hebDay == 26 and hebMonth == 9:
        return {0: 'Hanukka'}
    if hebDay == 27 and hebMonth == 9:
        return {0: 'Hanukka'}
    if hebDay == 28 and hebMonth == 9:
        return {0: 'Hanukka'}
    if hebDay == 29 and hebMonth == 9:
        return {0: 'Hanukka'}
    if len(Month(hebYear, 9)) == 30:
        if hebDay == 30 and hebMonth == 9:
            return {0: 'Hanukka'}
        elif hebDay == 1 and hebMonth == 10:
            return {0: 'Hanukka'}
        elif hebDay == 2 and hebMonth == 10:
            return {0: 'Hanukka'}
    else:  # if len(Month(hebYear, 9)) == 29:
        if hebDay == 1 and hebMonth == 10:
            return {0: 'Hanukka'}
        elif hebDay == 2 and hebMonth == 10:
            return {0: 'Hanukka'}
        elif hebDay == 3 and hebMonth == 10:
            return {0: 'Hanukka'}

    # Holidays in Shevat
    if hebDay == 15 and hebMonth == 11:
        return {0: 'TuBShvat'}

    # Holidays in Adar (I)/Adar II
    if Year(hebYear).leap:
        monthEsther = 13
    else:
        monthEsther = 12
    if hebDay == 14 and hebMonth == monthEsther:
        return {0: 'Purim', 3: 'Hag', 4: 'Shabbat'}
    elif hebDay == 15 and hebMonth == monthEsther:
        return {0: 'Purim', 3: 'Hag', 4: 'Shabbat'}  # Shushan Purim
Exemple #17
0
    def get_variable_days(self, year):
        days = super().get_variable_days(year)

        delta = timedelta(days=1)
        current_date = date(year, 1, 1)

        while current_date.year == year:
            hebrew_date = GregorianDate(
                year=current_date.year,
                month=current_date.month,
                day=current_date.day,
            ).to_heb()

            jewish_year = hebrew_date.year
            month = hebrew_date.month
            day = hebrew_date.day

            if month == 7:
                if day in {1, 2, 3}:
                    days.append((current_date, "Rosh Hashana"))
                elif day == 10:
                    days.append((current_date, "Yom Kippur"))
                elif day in range(15, 22):
                    days.append((current_date, "Sukkot"))
                elif day == 22:
                    days.append((current_date, "Shmini Atzeres"))
            elif month == 12 and not HebrewDate._is_leap(jewish_year):
                if day == 14:
                    days.append((current_date, "Purim"))
                if day == 15:
                    days.append((current_date, "Shushan Purim"))
            elif month == 13:
                if day == 14:
                    days.append((current_date, "Purim"))
                elif day == 15:
                    days.append((current_date, "Shushan Purim"))
            elif month == 1 and day in {15, 21}:
                days.append((current_date, "Pesach"))
            elif month == 2:
                if day == 5:
                    if hebrew_date.weekday() == 6:
                        days.append((
                            HebrewDate(jewish_year, month, 4).to_pydate(),
                            "Independence Day",
                        ))
                    elif hebrew_date.weekday() == 7:
                        days.append((
                            HebrewDate(jewish_year, month, 3).to_pydate(),
                            "Independence Day",
                        ))
                    elif hebrew_date.weekday() == 2:
                        days.append((
                            HebrewDate(jewish_year, month, 6).to_pydate(),
                            "Independence Day",
                        ))
                    else:
                        days.append((current_date, "Independence Day"))
            elif month == 3 and day == 6:
                days.append((current_date, "Shavout"))

            current_date += delta

        return days
Exemple #18
0
 def __len__(self):
     return HebrewDate._days_in_year(self.year)
Exemple #19
0
    def get_variable_days(self, year):
        days = super(Israel, self).get_variable_days(year)

        delta = timedelta(days=1)
        current_date = date(year, 1, 1)

        while current_date.year == year:
            hebrew_date = GregorianDate(
                year=current_date.year,
                month=current_date.month,
                day=current_date.day,
            ).to_heb()

            jewish_year = hebrew_date.year
            month = hebrew_date.month
            day = hebrew_date.day

            if month == 7:
                if day in {1, 2, 3}:
                    days.append((current_date, "Rosh Hashana"))
                elif day == 10:
                    days.append((current_date, "Yom Kippur"))
                elif day in range(15, 22):
                    days.append((current_date, "Sukkot"))
                elif day == 22:
                    days.append((current_date, "Shmini Atzeres"))
            elif month == 12:
                leap = HebrewDate._is_leap(jewish_year)
                if day == 14:
                    days.append((current_date, "Purim"))
                if day == 15 and not leap:
                    days.append((current_date, "Purim"))
            elif month == 13:
                if day == 14:
                    days.append((current_date, "Purim"))
                elif day == 15:
                    days.append((current_date, "Shushan Purim"))
            elif month == 1 and day in {15, 21}:
                days.append((current_date, "Pesach"))
            elif month == 2:
                if day == 5:
                    if hebrew_date.weekday() == 6:
                        days.append(
                            (
                                HebrewDate(jewish_year, month, 4).to_pydate(),
                                "Independence Day",
                            )
                        )
                    elif hebrew_date.weekday() == 7:
                        days.append(
                            (
                                HebrewDate(jewish_year, month, 3).to_pydate(),
                                "Independence Day",
                            )
                        )
                    elif hebrew_date.weekday() == 2:
                        days.append(
                            (
                                HebrewDate(jewish_year, month, 6).to_pydate(),
                                "Independence Day",
                            )
                        )
                    else:
                        days.append((current_date, "Independence Day"))
            elif month == 3 and day == 6:
                days.append((current_date, "Shavout"))

            current_date += delta

        return days
Exemple #20
0
 def _elapsed_months(self):
     '''Return number of months elapsed from beginning of calendar'''
     yearmonths = tuple(Year(self.year))
     months_elapsed = (HebrewDate._elapsed_months(self.year) +
                       yearmonths.index(self.month))
     return months_elapsed
Exemple #21
0
def test_weekday():
    assert GregorianDate(2017, 8, 7).weekday() == 2
    assert HebrewDate(5777, 6, 1).weekday() == 4
    assert JulianDay(2458342.5).weekday() == 1