Author tim.peters
Recipients belopolsky, exarkun, lemburg, madison.may, mark.dickinson, pitrou, tim.peters
Date 2013-08-03.17:44:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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 ;-)
Date User Action Args
2013-08-03 17:44:39tim.peterssetrecipients: + tim.peters, lemburg, exarkun, mark.dickinson, belopolsky, pitrou, madison.may
2013-08-03 17:44:39tim.peterssetmessageid: <>
2013-08-03 17:44:39tim.peterslinkissue18629 messages
2013-08-03 17:44:39tim.peterscreate