Why can't timedeltas be divided?
webograph
webograph at eml.cc
Sun Apr 27 02:48:22 CEST 2008
On Thu, 25 May 2006, maric wrote:
> > The ratio of two durations has no meaning???
> Oh, sorry, sure it has, I wanted to say "it has no meaning in timedelta provided arithmetic".
> It's a ratio (no dimension) not a duration. In that sense the expected result should be a float, and the proposed operator will break the timedelta's arithmetic consistence.
>
> t, u, v <- timedeltas
> t+u # valid
> t / u # valid
> t / u + v # invalid while all terms are valids
>
why is this a problem? not every structure has to form a closed
mathematical field, and there are other cases in which dividing similar
values yields another structure (think of calculating `factor =
speed2/speed1; distance2 = factor * distance1`)
is there any hope this can be fixed? defining timedelta/timedelta
division could not break existing code because no such division is
defined yet.
> num_weeks = (time_diff.days * 24* 3600 + time_diff.seconds) / (7.*24*3600)
this requires domain knowledge i'd expect a time structure to provide!
as you can create a timedelta by timedelta(seconds=1234567), i think it
is not too much to ask to have some simple way to get back the 1234567
seconds without thinking about what intervals (currently days, seconds
and microseconds) are used internally.
sorry for bringing up such an old thread, but this seems important to me
-- up to now, there are thousands [1] of python programs that use
hardcoded time calculations.
regards
webograph
[1]
http://www.google.com/codesearch?q=60|3600+24+timedelta+lang%3Apython
(gave me about 2000)
More information about the Python-list
mailing list