Skip to content

Commit 505ea1d

Browse files
committed
Add equality test
1 parent a69761e commit 505ea1d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/pendulum/tz/timezone.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from abc import ABC
88
from abc import abstractmethod
99
from typing import TYPE_CHECKING
10+
from typing import Any
1011
from typing import TypeVar
1112
from typing import cast
1213

@@ -66,6 +67,9 @@ def __new__(cls, key: str) -> Self:
6667
except zoneinfo.ZoneInfoNotFoundError:
6768
raise InvalidTimezone(key)
6869

70+
def __eq__(self, other: Any) -> bool:
71+
return isinstance(other, PendulumTimezone) and self.key == other.key
72+
6973
@property
7074
def name(self) -> str:
7175
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)