[New-bugs-announce] [issue2706] datetime: define division timedelta/timedelta
report at bugs.python.org
Sun Apr 27 23:04:07 CEST 2008
New submission from webograph <webograph at eml.cc>:
i suggest that division be defined for timedelta1/timedelta2, in that
sense that it gives how many times timedelta2 fits in timedelta1 (ie the
usual meaning of division), using integer arithmetics for floor division
(//) and returning float for truediv (/ after `from __future__ import
aside from the obvious how-many-times-does-a-fit-into-b, this solves the
issue of having individual methods for conversion to a number of
seconds, hours, days or nanocenturies (as described in #1673409).
from datetime import timedelta
duration = timedelta(hours=1.5, seconds=20)
print "Until the time is up, you can listen to 'We will rock you' %d
this issue follows a discussion on python-list, re-initiated by .
there have previously been similar feature requests on datetime, most of
which have been rejected due to ambiguities (e.g. ), conflicts with
time_t or issues with time zones.
the only issue i've seen that can be relevant here is the
integer-vs-float discussion, which is here handled by floordiv (//) and
i've written a patch against svn trunk revision 62520.
it uses function pointers to reduce code duplication; in case this
inappropriate here, i also have a pointerless version.
i familiar with c but not experienced, especially with the python ways
of writing c. most of the code is just adapted from other functions in
the same files, so it is probably, but should nevertheless checked with
i've also added test, but am not sure what has to be tested and what not.
only cases in which division would fail without the patch are changed.
this will be a problem if (and only if) someone divides unknown objects
and waits for TypeError to be raised.
such behavior is probably rare.
 <mid:4813CD56.40800 at eml.cc>,
components: Library (Lib)
title: datetime: define division timedelta/timedelta
type: feature request
Added file: http://bugs.python.org/file10126/datetime_datetime_division.patch
Tracker <report at bugs.python.org>
More information about the New-bugs-announce