Skip to content
Merged
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
12 changes: 9 additions & 3 deletions adafruit_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,15 @@ def microseconds(self):
# Instance methods
def total_seconds(self):
"""Return the total number of seconds contained in the duration."""
return (
(self._days * 86400 + self._seconds) * 10 ** 6 + self._microseconds
) / 10 ** 6
# If the duration is less than a threshold duration, and microseconds
# is nonzero, then the result is a float. Otherwise, the result is a
# (possibly long) integer. This differs from standard Python where the
# result is always a float, because the precision of CircuitPython
# floats is considerably smaller than on standard Python.
seconds = self._days * 86400 + self._seconds
if self._microseconds != 0 and abs(seconds) < (1 << 21):
seconds += self._microseconds / 10 ** 6
return seconds

def __repr__(self):
args = []
Expand Down