Skip to content

Commit fd360ac

Browse files
committed
Add equality test
1 parent f071ed3 commit fd360ac

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pendulum/tz/timezone.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from abc import ABC
66
from abc import abstractmethod
7-
from typing import cast
7+
from typing import Any, cast
88

99
from pendulum.tz.exceptions import AmbiguousTime
1010
from pendulum.tz.exceptions import InvalidTimezone
@@ -58,6 +58,9 @@ def __new__(cls, key: str) -> Timezone:
5858
except zoneinfo.ZoneInfoNotFoundError:
5959
raise InvalidTimezone(key)
6060

61+
def __eq__(self, other: Any) -> bool:
62+
return isinstance(other, PendulumTimezone) and self.key == other.key
63+
6164
@property
6265
def name(self) -> str:
6366
return self.key

tests/tz/test_timezone.py

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

4343

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

0 commit comments

Comments
 (0)