[ python-Feature Requests-1487389 ] datetime.time and datetime.timedelta

SourceForge.net noreply at sourceforge.net
Fri May 12 18:15:47 CEST 2006


Feature Requests item #1487389, was opened at 2006-05-12 09:13
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1487389&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
>Category: Python Library
>Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Chris Withers (fresh)
Assigned to: Nobody/Anonymous (nobody)
Summary: datetime.time and datetime.timedelta

Initial Comment:
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

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2006-05-12 12:15

Message:
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


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1487389&group_id=5470


More information about the Python-bugs-list mailing list