Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

- Fixed ISO week dates not being parsed properly in `fom_format()`.
- Fixed period `==` comparison raising an exception when compared with other types.


## [2.0.4] - 2018-10-30
Expand Down
13 changes: 8 additions & 5 deletions pendulum/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,11 @@ def __hash__(self):
return hash((self.start, self.end, self._absolute))

def __eq__(self, other):
return (self.start, self.end, self._absolute) == (
other.start,
other.end,
other._absolute,
)
try:
return (self.start, self.end, self._absolute) == (
other.start,
other.end,
other._absolute,
)
except AttributeError:
return NotImplemented
8 changes: 8 additions & 0 deletions tests/period/test_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ def test_comparison_to_timedelta():
period = dt2 - dt1

assert period < timedelta(days=4)

def test_comparison_with_other():
dt1 = pendulum.datetime(2016, 11, 18)
dt2 = pendulum.datetime(2016, 11, 20)
p = pendulum.period(dt1, dt2)

assert p != None
assert not p == None