[issue1673409] datetime module missing some important methods

STINNER Victor report at bugs.python.org
Fri Oct 31 19:12:26 CET 2008


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

New patch based on catlee's patch: add toseconds() method to timedelta 
but use the float type to keep the microseconds. The error between the 
exact value and IEEE754 value is small: the error is smaller than one 
second even with 999999999 days:

 - with less than 16 days, the microsecond error is smaller than 
0,01%.
 - with less than 1000 days, the microsecond error is smaller than 1%
 - with 99500 days or more, the microsecond error is bigger than 90%

To compute the error in microseconds:
>>> d=100; m=1
>>> e=abs((timedelta(days=d, microseconds=m).toseconds() - 
d*86400)*1e6 - m)
>>> e*100/m
0.024044513702392578

For the seconds, this is no error even with 999999999 days. Error in 
seconds:

>>> d=999999999; s=1; timedelta(days=d, seconds=m).toseconds() - 
d*86400, s
(1.0, 1)

(no error, both values are the same)

----------
keywords: +patch
Added file: http://bugs.python.org/file11919/timedelta_toseconds_float.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1673409>
_______________________________________


More information about the Python-bugs-list mailing list