This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: datetime.time and datetime.timedelta
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: fresh, skip.montanaro, tim.peters
Priority: normal Keywords:

Created on 2006-05-12 13:13 by fresh, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg54802 - (view) Author: Chris Withers (fresh) Date: 2006-05-12 13:13
print datetime.time(hour=0)+datetime.timedelta(hours=1) 

...gives...

TypeError: unsupported operand type(s) for +:
'datetime.time' and 'datetime.timedelta'

Which is a bit frustrating :-/

Does it really need to be this way?

Chris
msg54803 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2006-05-12 16:15
Logged In: YES 
user_id=31435

Since the lack of arithmetic on `time` objects is both
intended and documented, this isn't "a bug".  I moved this
to the Feature Requests tracker.

The problem with arithmetic on time objects is that it's not
obvious what to do in case of overflow or underflow:  wrap
around or raise OverflowError?  Either way violates _some_
reasonable expectation.  Embed your time in a `datetime`
object and then you can decide what you want to do.  For
example, if you want to wrap around,

>>> print (datetime.combine(date.today(), time(hour=0)) -
timedelta(hours=1)).time()
23:00:00
msg54804 - (view) Author: Chris Withers (fresh) Date: 2006-05-13 15:49
Logged In: YES 
user_id=24723

Well, I think the OverflowError is perfectly correct, and
lets the software author handle that situation in any way
they want.

That said, you could add a keyword option to the
datetime.time constructor to allow it either to wrap round,
or raise OverflowError, with the overflow being the default.

If I resulted up patches for these, how would I get them
into a python release?
msg55572 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2007-09-02 03:15
See this other issue I just closed:

    http://bugs.python.org/issue1118748
History
Date User Action Args
2022-04-11 14:56:17adminsetgithub: 43350
2007-09-02 03:16:07skip.montanarosetstatus: open -> closed
resolution: rejected
2007-09-02 03:15:28skip.montanarosetnosy: + skip.montanaro
messages: + msg55572
2006-05-12 13:13:40freshcreate