Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
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
7 changes: 7 additions & 0 deletions test/test_jewish_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import test.test_helper
from zmanim.hebrew_calendar.jewish_calendar import JewishCalendar
from zmanim.hebrew_calendar.jewish_date import JewishDate


class TestJewishCalendar(unittest.TestCase):
Expand Down Expand Up @@ -899,3 +900,9 @@ def test_sof_zman_kiddush_levana_between_moldos(self):
expected_time = first_molad + timedelta(microseconds=expected_offset)
# round for floating microsecond precision inconsistency
self.assertEqual(calendar.sof_zman_kiddush_levana_between_moldos().toordinal(), expected_time.toordinal())

def test_date_arithmetic_returns_inherited_type(self):
for instance, type in [(JewishCalendar(5783, 1, 1), JewishCalendar), (JewishDate(5783, 1, 1), JewishDate)]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep other types out of this batch of tests, JewishCalendar alone should suffice here. An alternative approach would be to test the method in TestJewishDate, and create a dummy class to ensure the type isn't being lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duly noted, indeed keeps the code-base clean.

self.assertIsInstance(instance, type)
instance += timedelta(days=1)
self.assertIsInstance(instance, type)
6 changes: 3 additions & 3 deletions zmanim/hebrew_calendar/jewish_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ def __add__(self, addend) -> 'JewishDate':
if isinstance(addend, int):
return copy.copy(self).forward(addend)
elif isinstance(addend, timedelta):
return JewishDate(self.gregorian_date + addend)
return type(self)(self.gregorian_date + addend)
raise ValueError

def __sub__(self, subtrahend):
if isinstance(subtrahend, int):
return copy.copy(self).back(subtrahend)
elif isinstance(subtrahend, timedelta):
return JewishDate(self.gregorian_date - subtrahend)
return type(self)(self.gregorian_date - subtrahend)
elif isinstance(subtrahend, JewishDate):
return self.gregorian_date - subtrahend.gregorian_date
elif isinstance(subtrahend, date):
Expand Down Expand Up @@ -535,4 +535,4 @@ def _chalakim_since_molad_tohu(year: int, month: int) -> int:
@staticmethod
def _month_number_from_tishrei(year: int, month: int) -> int:
leap = JewishDate._is_jewish_leap_year(year)
return 1 + ((month + (6 if leap else 5)) % (13 if leap else 12))
return 1 + ((month + (6 if leap else 5)) % (13 if leap else 12))