Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subtracting negative timedelta around DST #419

Merged
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
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()