Skip to content

Commit

Permalink
Implement equality per subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed Dec 26, 2024
1 parent 64e2553 commit 14b2b9e
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 @@ -67,7 +67,7 @@ def __new__(cls, key: str) -> Self:
raise InvalidTimezone(key)

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

@property
def name(self) -> str:
Expand Down Expand Up @@ -175,6 +175,9 @@ def __init__(self, offset: int, name: str | None = None) -> None:
self._offset = offset
self._utcoffset = _datetime.timedelta(seconds=offset)

def __eq__(self, other: object) -> bool:
return isinstance(other, FixedTimezone) and self._offset == other._offset

@property
def name(self) -> str:
return self._name
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 @@ -404,6 +404,11 @@ def test_fixed_timezone():
assert tz2.dst(dt) == timedelta()


def test_fixed_equality():
assert fixed_timezone(19800) == fixed_timezone(19800)
assert fixed_timezone(19800) != fixed_timezone(19801)


def test_just_before_last_transition():
tz = pendulum.timezone("Asia/Shanghai")
dt = datetime(1991, 4, 20, 1, 49, 8, fold=0)
Expand Down

0 comments on commit 14b2b9e

Please sign in to comment.