We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8012a7e commit 3020cefCopy full SHA for 3020cef
pendulum/duration.py
@@ -23,6 +23,10 @@ def _divide_and_round(a, b):
23
# Based on the reference implementation for divmod_near
24
# in Objects/longobject.c.
25
q, r = divmod(a, b)
26
+
27
+ if isinstance(q, float) and q == int(q):
28
+ q = int(q)
29
30
# round up if either r / b > 0.5, or r / b == 0.5 and q is odd.
31
# The expression r / b > 0.5 is equivalent to 2 * r > b if b is
32
# positive, 2 * r < b if b negative.
tests/duration/test_arithmetic.py
@@ -38,12 +38,24 @@ def test_divide():
38
assert isinstance(mul, pendulum.Duration)
39
assert_duration(mul, 0, 0, 0, 1, 0, 0, 17, 761111)
40
41
+ it = pendulum.duration(days=2, seconds=35, microseconds=522222)
42
+ mul = it / 1.1
43
44
+ assert isinstance(mul, pendulum.Duration)
45
+ assert_duration(mul, 0, 0, 0, 1, 19, 38, 43, 202020)
46
47
it = pendulum.duration(years=2, months=4, days=2, seconds=35, microseconds=522222)
48
mul = it / 2
49
50
51
assert_duration(mul, 1, 2, 0, 1, 0, 0, 17, 761111)
52
53
+ it = pendulum.duration(years=2, months=4, days=2, seconds=35, microseconds=522222)
54
+ mul = it / 2.0
55
56
57
+ assert_duration(mul, 1, 2, 0, 1, 0, 0, 17, 761111)
58
59
60
def test_floor_divide():
61
it = pendulum.duration(days=2, seconds=34, microseconds=522222)
0 commit comments