Skip to content

Commit

Permalink
Add equality test
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed Dec 19, 2024
1 parent a69761e commit cd9307b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/pendulum/tz/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from abc import abstractmethod
from typing import TYPE_CHECKING
from typing import TypeVar
from typing import cast
from typing import Any, cast

from pendulum.tz.exceptions import AmbiguousTime
from pendulum.tz.exceptions import InvalidTimezone
Expand Down Expand Up @@ -66,6 +66,9 @@ def __new__(cls, key: str) -> Self:
except zoneinfo.ZoneInfoNotFoundError:
raise InvalidTimezone(key)

def __eq__(self, other: Any) -> bool:
return isinstance(other, PendulumTimezone) and self.key == other.key

@property
def name(self) -> str:
return self.key
Expand Down
5 changes: 5 additions & 0 deletions tests/tz/test_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def test_basic_convert():
assert dt.tzinfo.dst(dt) == timedelta(seconds=3600)


def test_equality():
assert timezone("Europe/Paris") == timezone("Europe/Paris")
assert timezone("Europe/Paris") != timezone("Europe/Berlin")


def test_skipped_time_with_pre_rule():
dt = datetime(2013, 3, 31, 2, 30, 45, 123456, fold=0)
tz = timezone("Europe/Paris")
Expand Down

0 comments on commit cd9307b

Please sign in to comment.