classification
Title: enable time + timedelta
Type: Stage:
Components: Extension Modules Versions:
process
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.

Files
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 datetime1.date() == datetime2.date()"

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
comp.lang.python:

    http://mail.python.org/pipermail/python-list/2005-January/303023.html

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 = datetime.datetime.now().replace(hour=t.hour, minute=t.minute,
second=t.second)
>>> dt
datetime.datetime(2007, 9, 1, 11, 47, 0, 147616)
>>> for i in range(1, 10):
...   print (dt + i * td).time()
... 
22:53:40.148850
10:00:20.150084
21:07:00.151318
08:13:40.152552
19:20:20.153786
06:27:00.155020
17:33:40.156254
04:40:20.157488
15:47:00.158722
History
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