Skip to content

Commit

Permalink
feat(datetime): Update datetime __eq__ for different locales
Browse files Browse the repository at this point in the history
  • Loading branch information
mobinghoveoud committed Nov 15, 2024
1 parent 2f067c4 commit fc5a63c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions jdatetime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,10 @@ def __eq__(self, other_datetime):
if other_datetime is None:
return False

other_locale = other_datetime.locale if isinstance(other_datetime, datetime) else get_locale()
if self.locale != other_locale:
return False

if isinstance(other_datetime, datetime):
other_datetime = other_datetime.togregorian()

Expand Down
5 changes: 3 additions & 2 deletions tests/test_jdatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,10 +748,11 @@ def test_eq_datetime_diff_tz(self):
jdt_teh = jdatetime.datetime(1389, 2, 17, 3, 30, 0, tzinfo=teh)
self.assertEqual(jdt_teh, jdt_gmt)

def test_eq_datetimes_with_different_locales_are_equal(self):
def test_eq_datetimes_with_different_locales_are_not_equal(self):
dt_en = jdatetime.datetime(2018, 4, 15, 0, 0, 0, locale='en_US')
dt_fa = jdatetime.datetime(2018, 4, 15, 0, 0, 0, locale='fa_IR')
self.assertEqual(dt_en, dt_fa)
self.assertNotEqual(dt_en, dt_fa)
self.assertNotEqual(dt_fa, dt_en)

def test_eq_with_none(self):
dt1 = jdatetime.datetime(2023, 9, 30, 12, 0, 0, locale='fa_IR')
Expand Down

0 comments on commit fc5a63c

Please sign in to comment.