Skip to content

Commit cd9307b

Browse files
committed
Add equality test
1 parent a69761e commit cd9307b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/pendulum/tz/timezone.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from abc import abstractmethod
99
from typing import TYPE_CHECKING
1010
from typing import TypeVar
11-
from typing import cast
11+
from typing import Any, cast
1212

1313
from pendulum.tz.exceptions import AmbiguousTime
1414
from pendulum.tz.exceptions import InvalidTimezone
@@ -66,6 +66,9 @@ def __new__(cls, key: str) -> Self:
6666
except zoneinfo.ZoneInfoNotFoundError:
6767
raise InvalidTimezone(key)
6868

69+
def __eq__(self, other: Any) -> bool:
70+
return isinstance(other, PendulumTimezone) and self.key == other.key
71+
6972
@property
7073
def name(self) -> str:
7174
return self.key

tests/tz/test_timezone.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def test_basic_convert():
4242
assert dt.tzinfo.dst(dt) == timedelta(seconds=3600)
4343

4444

45+
def test_equality():
46+
assert timezone("Europe/Paris") == timezone("Europe/Paris")
47+
assert timezone("Europe/Paris") != timezone("Europe/Berlin")
48+
49+
4550
def test_skipped_time_with_pre_rule():
4651
dt = datetime(2013, 3, 31, 2, 30, 45, 123456, fold=0)
4752
tz = timezone("Europe/Paris")

0 commit comments

Comments
 (0)