From 7c2563ff223528528d82b6314d004d9088792da9 Mon Sep 17 00:00:00 2001 From: Jacob Shilitz Date: Mon, 14 Feb 2022 12:18:08 -0500 Subject: [PATCH 1/3] Add significant shabbos implantation with tests --- test/test_jewish_calendar.py | 196 ++++++++++++++++++++++ zmanim/hebrew_calendar/jewish_calendar.py | 22 +++ 2 files changed, 218 insertions(+) diff --git a/test/test_jewish_calendar.py b/test/test_jewish_calendar.py index 37497e3..aa0cdb0 100644 --- a/test/test_jewish_calendar.py +++ b/test/test_jewish_calendar.py @@ -677,6 +677,202 @@ def test_day_of_omer_outside_of_omer(self): calendar = JewishCalendar(test.test_helper.standard_monday_chaseirim(), 7, 1) self.assertIsNone(calendar.day_of_omer()) + def test_significant_shabbes_for_standard_monday_chaseirim(self): + year = test.test_helper.standard_monday_chaseirim() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-6'], + 'parshas_shekalim': ['11-29'], + 'parshas_zachor': ['12-13'], + 'parshas_parah': ['12-20'], + 'parshas_hachodesh': ['12-27'], + 'shabbos_hagadol': ['1-12'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_standard_monday_shelaimim(self): + year = test.test_helper.standard_monday_shelaimim() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-6'], + 'parshas_shekalim': ['11-27'], + 'parshas_zachor': ['12-11'], + 'parshas_parah': ['12-18'], + 'parshas_hachodesh': ['12-25'], + 'shabbos_hagadol': ['1-10'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_standard_tuesday_kesidran(self): + year = test.test_helper.standard_tuesday_kesidran() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-5'], + 'parshas_shekalim': ['11-27'], + 'parshas_zachor': ['12-11'], + 'parshas_parah': ['12-18'], + 'parshas_hachodesh': ['12-25'], + 'shabbos_hagadol': ['1-10'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_standard_thursday_kesidran(self): + year = test.test_helper.standard_thursday_kesidran() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-3'], + 'parshas_shekalim': ['11-25'], + 'parshas_zachor': ['12-9'], + 'parshas_parah': ['12-23'], + 'parshas_hachodesh': ['1-1'], + 'shabbos_hagadol': ['1-8'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_standard_thursday_shelaimim(self): + year = test.test_helper.standard_thursday_shelaimim() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-3'], + 'parshas_shekalim': ['12-1'], + 'parshas_zachor': ['12-8'], + 'parshas_parah': ['12-22'], + 'parshas_hachodesh': ['12-29'], + 'shabbos_hagadol': ['1-14'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_standard_shabbos_chaseirim(self): + year = test.test_helper.standard_shabbos_chaseirim() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-8'], + 'parshas_shekalim': ['12-1'], + 'parshas_zachor': ['12-8'], + 'parshas_parah': ['12-22'], + 'parshas_hachodesh': ['12-29'], + 'shabbos_hagadol': ['1-14'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_standard_shabbos_shelaimim(self): + year = test.test_helper.standard_shabbos_shelaimim() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-8'], + 'parshas_shekalim': ['11-29'], + 'parshas_zachor': ['12-13'], + 'parshas_parah': ['12-20'], + 'parshas_hachodesh': ['12-27'], + 'shabbos_hagadol': ['1-12'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_leap_monday_chaseirim(self): + year = test.test_helper.leap_monday_chaseirim() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-6'], + 'parshas_shekalim': ['12-27'], + 'parshas_zachor': ['13-11'], + 'parshas_parah': ['13-18'], + 'parshas_hachodesh': ['13-25'], + 'shabbos_hagadol': ['1-10'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_leap_monday_shelaimim(self): + year = test.test_helper.leap_monday_shelaimim() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-6'], + 'parshas_shekalim': ['12-25'], + 'parshas_zachor': ['13-9'], + 'parshas_parah': ['13-23'], + 'parshas_hachodesh': ['1-1'], + 'shabbos_hagadol': ['1-8'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_leap_tuesday_kesidran(self): + year = test.test_helper.leap_tuesday_kesidran() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-5'], + 'parshas_shekalim': ['12-25'], + 'parshas_zachor': ['13-9'], + 'parshas_parah': ['13-23'], + 'parshas_hachodesh': ['1-1'], + 'shabbos_hagadol': ['1-8'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_leap_thursday_chaseirim(self): + year = test.test_helper.leap_thursday_chaseirim() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-3'], + 'parshas_shekalim': ['13-1'], + 'parshas_zachor': ['13-8'], + 'parshas_parah': ['13-22'], + 'parshas_hachodesh': ['13-29'], + 'shabbos_hagadol': ['1-14'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_leap_thursday_shelaimim(self): + year = test.test_helper.leap_thursday_shelaimim() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-3'], + 'parshas_shekalim': ['12-29'], + 'parshas_zachor': ['13-13'], + 'parshas_parah': ['13-20'], + 'parshas_hachodesh': ['13-27'], + 'shabbos_hagadol': ['1-12'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_leap_shabbos_chaseirim(self): + year = test.test_helper.leap_shabbos_chaseirim() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-8'], + 'parshas_shekalim': ['12-29'], + 'parshas_zachor': ['13-13'], + 'parshas_parah': ['13-20'], + 'parshas_hachodesh': ['13-27'], + 'shabbos_hagadol': ['1-12'] + } + self.assertEqual(result, expected) + + def test_significant_shabbes_for_leap_shabbos_shelaimim(self): + year = test.test_helper.leap_shabbos_shelaimim() + + result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) + expected = { + 'shabbos_shuva': ['7-8'], + 'parshas_shekalim': ['12-27'], + 'parshas_zachor': ['13-11'], + 'parshas_parah': ['13-18'], + 'parshas_hachodesh': ['13-25'], + 'shabbos_hagadol': ['1-10'] + } + self.assertEqual(result, expected) + def test_molad_as_datetime(self): expected_offset = (2, 20, 56, 496000) # UTC is 2:20:56.496 behind Jerusalem Local Time calendar = JewishCalendar(5776, 8, 1) diff --git a/zmanim/hebrew_calendar/jewish_calendar.py b/zmanim/hebrew_calendar/jewish_calendar.py index 6800ed0..1f976f6 100644 --- a/zmanim/hebrew_calendar/jewish_calendar.py +++ b/zmanim/hebrew_calendar/jewish_calendar.py @@ -37,6 +37,28 @@ def __repr__(self): def significant_day(self) -> Optional[str]: return getattr(self, f'_{self.jewish_month_name()}_significant_day', None)() + def significant_shabbos(self) -> Optional[str]: + if self.day_of_week != 7: + return None + if self.jewish_month == 1: + if self.jewish_day == 1: + return 'parshas_hachodesh' + elif self.jewish_day in range(8, 15): + return 'shabbos_hagadol' + elif self.jewish_month == 7 and self.jewish_day in range(3, 10): + return 'shabbos_shuva' + elif self.jewish_month == (self.months_in_jewish_year() - 1) and self.jewish_day in range(25, 31): + return 'parshas_shekalim' + elif self.jewish_month == self.months_in_jewish_year(): + if self.jewish_day == 1: + return 'parshas_shekalim' + elif self.jewish_day in range(7, 14): + return 'parshas_zachor' + elif self.jewish_day in range(17, 24): + return 'parshas_parah' + elif self.jewish_day in range(24, 30): + return 'parshas_hachodesh' + def is_assur_bemelacha(self) -> bool: return self.day_of_week == 7 or self.is_yom_tov_assur_bemelacha() From 51f5d8b288a872657f7ebf25554d9c5541f2b19e Mon Sep 17 00:00:00 2001 From: Jacob Shilitz Date: Fri, 25 Mar 2022 15:49:29 -0400 Subject: [PATCH 2/3] fix the spelling for 'shabbos' in the test method names to match the rest of the code --- test/test_jewish_calendar.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/test_jewish_calendar.py b/test/test_jewish_calendar.py index aa0cdb0..000526a 100644 --- a/test/test_jewish_calendar.py +++ b/test/test_jewish_calendar.py @@ -677,7 +677,7 @@ def test_day_of_omer_outside_of_omer(self): calendar = JewishCalendar(test.test_helper.standard_monday_chaseirim(), 7, 1) self.assertIsNone(calendar.day_of_omer()) - def test_significant_shabbes_for_standard_monday_chaseirim(self): + def test_significant_shabbos_for_standard_monday_chaseirim(self): year = test.test_helper.standard_monday_chaseirim() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -691,7 +691,7 @@ def test_significant_shabbes_for_standard_monday_chaseirim(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_standard_monday_shelaimim(self): + def test_significant_shabbos_for_standard_monday_shelaimim(self): year = test.test_helper.standard_monday_shelaimim() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -705,7 +705,7 @@ def test_significant_shabbes_for_standard_monday_shelaimim(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_standard_tuesday_kesidran(self): + def test_significant_shabbos_for_standard_tuesday_kesidran(self): year = test.test_helper.standard_tuesday_kesidran() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -719,7 +719,7 @@ def test_significant_shabbes_for_standard_tuesday_kesidran(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_standard_thursday_kesidran(self): + def test_significant_shabbos_for_standard_thursday_kesidran(self): year = test.test_helper.standard_thursday_kesidran() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -733,7 +733,7 @@ def test_significant_shabbes_for_standard_thursday_kesidran(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_standard_thursday_shelaimim(self): + def test_significant_shabbos_for_standard_thursday_shelaimim(self): year = test.test_helper.standard_thursday_shelaimim() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -747,7 +747,7 @@ def test_significant_shabbes_for_standard_thursday_shelaimim(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_standard_shabbos_chaseirim(self): + def test_significant_shabbos_for_standard_shabbos_chaseirim(self): year = test.test_helper.standard_shabbos_chaseirim() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -761,7 +761,7 @@ def test_significant_shabbes_for_standard_shabbos_chaseirim(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_standard_shabbos_shelaimim(self): + def test_significant_shabbos_for_standard_shabbos_shelaimim(self): year = test.test_helper.standard_shabbos_shelaimim() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -775,7 +775,7 @@ def test_significant_shabbes_for_standard_shabbos_shelaimim(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_leap_monday_chaseirim(self): + def test_significant_shabbos_for_leap_monday_chaseirim(self): year = test.test_helper.leap_monday_chaseirim() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -789,7 +789,7 @@ def test_significant_shabbes_for_leap_monday_chaseirim(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_leap_monday_shelaimim(self): + def test_significant_shabbos_for_leap_monday_shelaimim(self): year = test.test_helper.leap_monday_shelaimim() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -803,7 +803,7 @@ def test_significant_shabbes_for_leap_monday_shelaimim(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_leap_tuesday_kesidran(self): + def test_significant_shabbos_for_leap_tuesday_kesidran(self): year = test.test_helper.leap_tuesday_kesidran() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -817,7 +817,7 @@ def test_significant_shabbes_for_leap_tuesday_kesidran(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_leap_thursday_chaseirim(self): + def test_significant_shabbos_for_leap_thursday_chaseirim(self): year = test.test_helper.leap_thursday_chaseirim() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -831,7 +831,7 @@ def test_significant_shabbes_for_leap_thursday_chaseirim(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_leap_thursday_shelaimim(self): + def test_significant_shabbos_for_leap_thursday_shelaimim(self): year = test.test_helper.leap_thursday_shelaimim() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -845,7 +845,7 @@ def test_significant_shabbes_for_leap_thursday_shelaimim(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_leap_shabbos_chaseirim(self): + def test_significant_shabbos_for_leap_shabbos_chaseirim(self): year = test.test_helper.leap_shabbos_chaseirim() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) @@ -859,7 +859,7 @@ def test_significant_shabbes_for_leap_shabbos_chaseirim(self): } self.assertEqual(result, expected) - def test_significant_shabbes_for_leap_shabbos_shelaimim(self): + def test_significant_shabbos_for_leap_shabbos_shelaimim(self): year = test.test_helper.leap_shabbos_shelaimim() result = test.test_helper.all_days_matching(year, lambda c: c.significant_shabbos()) From aabbf238a0bd0bdd50a3f037fa4b56bd18a3e61d Mon Sep 17 00:00:00 2001 From: Jacob Shilitz Date: Fri, 25 Mar 2022 15:53:55 -0400 Subject: [PATCH 3/3] Add change log for `significant_shabbos()` --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0d9c9e..387c46e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - `jewish_calendar.is_taanis_bechorim()` function added - `jewish_calendar.is_shabbos_mevorchim()` function added +- `jewish_calendar.significant_shabbos()` function added ## [0.3.1] - 2020-11-05 ### Added