From 9fefc2429b4c5293e053699f129f8c2f078f7f40 Mon Sep 17 00:00:00 2001 From: NateScarlet Date: Wed, 20 Jun 2018 11:33:22 +0800 Subject: [PATCH 1/2] Fix issue #238: wrong position swap code. --- .gitignore | 4 ++++ pendulum/_extensions/helpers.py | 4 ---- tests/test_helpers.py | 8 ++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b7480daa..f1152e6f 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,7 @@ profile.html /wheelhouse /docs/site/* pyproject.lock + +# editor + +.vscode \ No newline at end of file diff --git a/pendulum/_extensions/helpers.py b/pendulum/_extensions/helpers.py index c8b57f34..0c07a9ee 100644 --- a/pendulum/_extensions/helpers.py +++ b/pendulum/_extensions/helpers.py @@ -282,10 +282,6 @@ def precise_diff(d1, d2): hour_diff += 24 d_diff -= 1 - if d1 > d2: - d1, d2 = d2, d1 - sign = -1 - y_diff = d2.year - d1.year m_diff = d2.month - d1.month d_diff += d2.day - d1.day diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 134892ca..ddd5d06c 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -115,6 +115,14 @@ def test_precise_diff_timezone(): days=1, hours=5 ) + # Issue238 + dt1 = timezone('UTC').datetime(2018, 6, 20, 1, 30) + dt2 = timezone('Asia/ShangHai').datetime(2018, 6, 20, 10, 30) # UTC+8 + diff = precise_diff(dt1, dt2) + assert_diff( + diff, + hours=1 + ) def test_week_day(): assert 5 == week_day(2017, 6, 2) From 4fc650d4a3119efce4246537a56becd7ad826328 Mon Sep 17 00:00:00 2001 From: NateScarlet Date: Wed, 20 Jun 2018 11:52:52 +0800 Subject: [PATCH 2/2] Fix test for travisCI: use other supported timezone --- tests/test_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index ddd5d06c..9bb57f3a 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -117,11 +117,11 @@ def test_precise_diff_timezone(): # Issue238 dt1 = timezone('UTC').datetime(2018, 6, 20, 1, 30) - dt2 = timezone('Asia/ShangHai').datetime(2018, 6, 20, 10, 30) # UTC+8 + dt2 = timezone('Europe/Paris').datetime(2018, 6, 20, 3, 40) # UTC+2 diff = precise_diff(dt1, dt2) assert_diff( diff, - hours=1 + minutes=10 ) def test_week_day():