Skip to content

Commit 0a40544

Browse files
committed
Fixed bug caused by microseconds being stored as floats on python2.
1 parent cc76d51 commit 0a40544

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pendulum/duration.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def __new__(
7979
if total < 0:
8080
m = -1
8181

82-
self._microseconds = round(total % m * 1e6)
82+
# round returns a float in python2, so ensure stored as an int
83+
self._microseconds = int(round(total % m * 1e6))
8384
self._seconds = abs(int(total)) % SECONDS_PER_DAY * m
8485

8586
_days = abs(int(total)) // SECONDS_PER_DAY * m
@@ -275,7 +276,7 @@ def to_iso8601_string(self):
275276
# no division to avoid possible floating point errors
276277
if not s:
277278
s = "0"
278-
s += ".{:0>6}".format(self.microseconds).rstrip("0")
279+
s += ".{:0>6d}".format(self.microseconds).rstrip("0")
279280
if s:
280281
time += "{}S".format(s)
281282
if len(time) > 1:

0 commit comments

Comments
 (0)