Message105192
This is correct behaviour. Note that .seconds is only one of the three attributes that contribute to the value of a timedelta: the others are .microseconds and .days. A timedelta is normalised in such a way that td.seconds and td.microseconds are always nonnegative; this means that td.days will be strictly negative for negative timedeltas. In your case the timedelta will have a .days attribute of -1, and the total time represented (e.g., in seconds, 86400.0 * td.days + td.seconds + 0.000001 * td.microseconds) will be small and negative.
Here's what I get on my system (in the py3k branch):
Python 3.2a0 (py3k:80840:80842, May 7 2010, 12:29:35)
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> td = datetime.datetime.now() - datetime.datetime.now()
>>> td.microseconds, td.seconds, td.days
(998977, 86399, -1)
>>> print(td)
-1 day, 23:59:59.998977
>>> 1e-6 * td.microseconds + td.seconds + 86400 * td.days
-0.0010230000043520704
>>> td.total_seconds() # new in Python 2.7, 3.2
-0.0010230000043520704 |
|
Date |
User |
Action |
Args |
2010-05-07 11:33:27 | mark.dickinson | set | recipients:
+ mark.dickinson, mykhal |
2010-05-07 11:33:26 | mark.dickinson | set | messageid: <1273232006.98.0.593760712838.issue8643@psf.upfronthosting.co.za> |
2010-05-07 11:33:24 | mark.dickinson | link | issue8643 messages |
2010-05-07 11:33:23 | mark.dickinson | create | |
|