Skip to content

Commit 5b06241

Browse files
committed
Fix offset error when subtracting datetimes in the same tz
1 parent e0f4030 commit 5b06241

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## [Unreleased]
4+
5+
### Fixed
6+
7+
- Fixed an offset error when subtracting datetimes in the same timezone.
8+
9+
310
## [1.4.1] - 2018-02-05
411

512
### Fixed

pendulum/helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ def precise_diff(d1, d2):
194194
if hasattr(d2, 'hour'):
195195
# If we are not in the same timezone
196196
# we need to adjust
197-
if not in_same_tz:
197+
#
198+
# We also need to adjust if we do not
199+
# have variable-length units
200+
if not in_same_tz or total_days == 0:
198201
offset1 = d1.utcoffset()
199202
offset2 = d2.utcoffset()
200203

tests/period_tests/test_add_subtract.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ def test_dst_add():
1212
assert new_end == end
1313

1414

15+
def test_dst_add_non_variable_units():
16+
start = pendulum.create(2013, 3, 31, 1, 30, tz='Europe/Paris')
17+
end = start.add(hours=1)
18+
period = end - start
19+
new_end = start + period
20+
21+
assert new_end == end
22+
23+
1524
def test_dst_subtract():
1625
start = pendulum.create(2017, 3, 7, tz='America/Toronto')
1726
end = start.add(days=6)

0 commit comments

Comments
 (0)