Tim Peters added the comment:

Well, a timedelta is a duration.  timedelta // n is as close as possible to one 
n'th of that duration, but "rounding down" (if necessary) so that the result is 
representable as a timedelta.  In the same way, if i and j are integers, i // j 
is as close as possible to one j'th of i, but "rounding down" (if necessary) so 
that the result is representable as an integer.  Like:

>>> from datetime import timedelta
>>> timedelta(1) // 7
datetime.timedelta(0, 12342, 857142)
>>> timedelta(1) - 7 * _
datetime.timedelta(0, 0, 6)
>>>

The last line shows the part truncated away:  one seventh of a day is not 
representable as a timedetla. If `timedelta // int` rounded to the closest 
representable timedelta, it would return timedelta(0, 12342, 857143) instead.  
That's a little bigger than a seventh of a day:

>>> timedelta(0, 12342, 857143) * 7
datetime.timedelta(1, 0, 1)

It has nothing directly to do with days, hours, seconds ... it so happens that 
timedelta has microsecond resolution, so the closest representable 
approximations to one n'th of a timedelta most often have non-zero microsecond 
components.  If timedelta had femtosecond resolution, they'd most often have 
non-zero femtosecond components ;-)

----------
nosy: +tim_one

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18629>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to