Title: enable time + timedelta
Type: Stage:
Components: Extension Modules Versions:
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: josh-sf, skip.montanaro
Priority: normal Keywords: patch

Created on 2005-02-08 16:56 by josh-sf, last changed 2007-09-02 03:13 by skip.montanaro. This issue is now closed.

File name Uploaded Description Edit
timedelta.diff josh-sf, 2005-02-08 16:56
Messages (2)
msg47733 - (view) Author: Josh (josh-sf) Date: 2005-02-08 16:56
This patch enables timedelta arithmetic for times (in
addition to dates and datetimes). Tests and doc included

Here's a response to the probable reason why this
hasn't been enabled already...

Times greater than 24 hours should not raise an
exception, but always wrap around. Any other behavior
is too surprising. (People expect to be able to call
you up at 11pm, and say "meet me in two hours" (if
you're a night person)).

Clock time is cyclical. Though it's convenient to
assign hours numbers, an unqualified hour 23.5 is not
naturally "greater than" hour 0.5. (Though I'm not
suggesting that we break this.)

The special meaning for hour 0 is only relevant for
datetimes. When dates are not involved, it shouldn't
get any special treatment. When dates are involved,
it's easy to "assert =="

If this change is made however, maybe
datetime.timedelta(hours=-1) should no longer normalize
to datetime.timedelta(-1, 82800)
msg55571 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2007-09-02 03:13
This has come up and been
rejected because there are so many
end cases.  Here's an item from a
thread I believe you started on

If you want to add time and timedelta objects,
use datetime objects and extract their times.
The behavior is well-defined.

>>> t = datetime.time(11, 47, 00)
>>> td = datetime.timedelta(0, 40000, 1234)
>>> dt =, minute=t.minute,
>>> dt
datetime.datetime(2007, 9, 1, 11, 47, 0, 147616)
>>> for i in range(1, 10):
...   print (dt + i * td).time()
Date User Action Args
2007-09-02 03:13:12skip.montanarosetstatus: open -> closed
resolution: rejected
messages: + msg55571
nosy: + skip.montanaro
2005-02-08 16:56:12josh-sfcreate