classification
Title: mistake in the timedelta.total_seconds docstring
Type: behavior Stage:
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: allo, docs@python, tim.peters
Priority: normal Keywords:

Created on 2013-08-24 22:05 by allo, last changed 2013-08-24 22:31 by allo. This issue is now closed.

Messages (3)
msg196100 - (view) Author: Alexander Schier (allo) Date: 2013-08-24 22:05
> Return the total number of seconds contained in the duration. Equivalent to (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 computed with true division enabled.

Should be
> Return the total number of seconds contained in the duration. Equivalent to (td.microseconds / 10**6 + (td.seconds + td.days * 24 * 3600) * 10**6) computed with true division enabled.

At least i hope, the bug is only in the docs and not in the function ;).
msg196101 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2013-08-24 22:14
The docs look correct to me.  For example,

>>> from datetime import *
>>> td = datetime.now() - datetime(1,1,1)
>>> td
datetime.timedelta(735103, 61756, 484000)
>>> td.total_seconds()
63512960956.484
                                                                ^
What the docs say match that output:

>>> (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 1e6
63512960956.484

Your suggestion's output:

>>> (td.microseconds / 1e6 + (td.seconds + td.days * 24 * 3600) * 10**6)
6.3512960956e+16

You're multiplying the number seconds by a million - not a good idea ;-)
msg196102 - (view) Author: Alexander Schier (allo) Date: 2013-08-24 22:31
Err, sorry my fault. Too late in the evening ;).

I saw the division by one million, but not the multiplation by one million before. Additionally i was confused, because i expected that seconds are added to each other in the parenthesis.

closing.
History
Date User Action Args
2013-08-24 22:31:42allosetstatus: open -> closed
resolution: not a bug
messages: + msg196102
2013-08-24 22:14:29tim.peterssetnosy: + tim.peters
messages: + msg196101
2013-08-24 22:05:21allocreate