Skip to content

Commit

Permalink
Fix subtracting negative timedelta around DST (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomage authored Jul 4, 2020
1 parent 51d2f69 commit 4fd7174
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 1 addition & 3 deletions pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,7 @@ def _subtract_timedelta(self, delta):
microseconds=delta.microseconds,
)

return self.subtract(
days=delta.days, seconds=delta.seconds, microseconds=delta.microseconds
)
return self.subtract(seconds=delta.total_seconds())

# DIFFERENCES

Expand Down
15 changes: 15 additions & 0 deletions tests/datetime/test_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,18 @@ def test_subtract_invalid_type():

with pytest.raises(TypeError):
"ab" - d


def test_subtract_negative_over_dls_transitioning_off():
just_before_dls_ends = pendulum.datetime(
2019, 11, 3, 1, 30, tz="US/Pacific", dst_rule=pendulum.PRE_TRANSITION
)
plus_10_hours = just_before_dls_ends + timedelta(hours=10)
minus_neg_10_hours = just_before_dls_ends - timedelta(hours=-10)

# 1:30-0700 becomes 10:30-0800
assert plus_10_hours.hour == 10
assert minus_neg_10_hours.hour == 10
assert just_before_dls_ends.is_dst()
assert not plus_10_hours.is_dst()
assert not minus_neg_10_hours.is_dst()

0 comments on commit 4fd7174

Please sign in to comment.