Very interesting - I would also expect it to work. I just wrote a function with some / doctests examples that does this in Python 2.x. Also published as an ActiveState recipe :
import datetime def divide_timedelta(td, divisor): """Python 2.x timedelta doesn't support division by float, this function does. >>> td = datetime.timedelta(10, 100, 1000) >>> divide_timedelta(td, 2) == td / 2 True >>> divide_timedelta(td, 100) == td / 100 True >>> divide_timedelta(td, 0.5) datetime.timedelta(20, 200, 2000) >>> divide_timedelta(td, 0.3) datetime.timedelta(33, 29133, 336667) >>> divide_timedelta(td, 2.5) datetime.timedelta(4, 40, 400) >>> td / 0.5 Traceback (most recent call last): ... TypeError: unsupported operand type(s) for /: 'datetime.timedelta' and 'float' """
source share