Skip to content

Commit

Permalink
Created _four_parshios function and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
simlist committed Sep 10, 2024
1 parent 6759144 commit 7a31af4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/pyluach/parshios.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,39 @@ class _Parshios_Enum(IntEnum):
VEZOS_HABERACHAH = auto()


class _FourParshiosEnum(Enum):
SHEKALIM = auto()
ZACHOR = auto()
PARAH = auto()
HACHODESH = auto()


def _get_four_parshios(date):
year = date.year
if _is_leap(year):
adar = 13
else:
adar = 12
shabbos = date.shabbos()
rc_adar = HebrewDate(year, adar, 1)
rc_nisan = HebrewDate(year, 1, 1)
if shabbos == rc_nisan:
return _FourParshiosEnum.HACHODESH
if shabbos <= rc_adar and rc_adar - shabbos < 7:
return _FourParshiosEnum.SHEKALIM
if shabbos.month == adar:
purim = HebrewDate(year, adar, 14)
if shabbos < purim and (purim - shabbos) < 7:
return _FourParshiosEnum.ZACHOR
if shabbos > purim and (shabbos - purim) in [8, 9]:
return _FourParshiosEnum.PARAH
if shabbos > purim and shabbos - purim < 7:
return _FourParshiosEnum.PARAH
if (rc_nisan - date) < 7:
return _FourParshiosEnum.HACHODESH
return None


PARSHIOS_HEBREW = [
'בראשית', 'נח', 'לך לך', 'וירא', 'חיי שרה', 'תולדות', 'ויצא', 'וישלח',
'וישב', 'מקץ', 'ויגש', 'ויחי', 'שמות', 'וארא', 'בא', 'בשלח', 'יתרו',
Expand Down
31 changes: 31 additions & 0 deletions tests/test_parshios.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pyluach import parshios, dates
from pyluach.parshios import _FourParshiosEnum


KNOWN_VALUES = {
Expand Down Expand Up @@ -71,3 +72,33 @@ def test_get_parshastring_hebrew():
assert parshios.getparsha_string(date, hebrew=True) == 'קרח'
date2 = dates.GregorianDate(2021, 7, 10)
assert parshios.getparsha_string(date2, hebrew=True) == 'מטות, מסעי'


def test_shekalim():
date = dates.HebrewDate(5785, 11, 25)
assert (
parshios._get_four_parshios(date) == _FourParshiosEnum.SHEKALIM
)
assert parshios._get_four_parshios(date - 1) is None
assert parshios._get_four_parshios(date + 7) != _FourParshiosEnum.SHEKALIM


def test_zachor():
date = dates.HebrewDate(5785, 12, 2)
assert (
parshios._get_four_parshios(date) == _FourParshiosEnum.ZACHOR
)


def test_parah():
date = dates.HebrewDate(5785, 12, 21)
assert parshios._get_four_parshios(date) == _FourParshiosEnum.PARAH
date = dates.HebrewDate(5784, 13, 14)
assert parshios._get_four_parshios(date) == _FourParshiosEnum.PARAH
assert parshios._get_four_parshios(date - 1) != _FourParshiosEnum.PARAH

def test_hachodesh():
date = dates.HebrewDate(5785, 12, 29)
assert parshios._get_four_parshios(date) == _FourParshiosEnum.HACHODESH
date = dates.HebrewDate(5782, 1, 1)
assert parshios._get_four_parshios(date) == _FourParshiosEnum.HACHODESH

0 comments on commit 7a31af4

Please sign in to comment.