From fc5a63c977af5592024269d09853e15201ce4409 Mon Sep 17 00:00:00 2001 From: Mobin Ghoveoud Date: Sat, 16 Nov 2024 03:15:48 +0330 Subject: [PATCH] feat(datetime): Update datetime __eq__ for different locales --- jdatetime/__init__.py | 4 ++++ tests/test_jdatetime.py | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/jdatetime/__init__.py b/jdatetime/__init__.py index 2872d82..97fcb45 100644 --- a/jdatetime/__init__.py +++ b/jdatetime/__init__.py @@ -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() diff --git a/tests/test_jdatetime.py b/tests/test_jdatetime.py index 4d8c84a..f8b82cf 100644 --- a/tests/test_jdatetime.py +++ b/tests/test_jdatetime.py @@ -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')