[Python-Dev] datetime.timedelta total_microseconds

Nick Coghlan ncoghlan at gmail.com
Sat Feb 16 12:38:01 EST 2019

On Sun, 17 Feb 2019 at 03:20, Paul Ganssle <paul at ganssle.io> wrote:
> I think if we add such a function, it will essentially be just a slower version of something that already exists. I suspect the main reason the "divide the timedelta by the interval" thing isn't a common enough idiom that people see it all the time is that it's only supported in Python 3. As more code drops Python 2, I think the "td / interval" idiom will hopefully become common enough that it will obviate the need for a total_duration function.

And personally, the total_seconds() case has always been enough for me.

> That said, if people feel very strongly that a total_duration function would be useful, maybe the best thing to do would be for me to add it to dateutil.utils? In that case it would at least be available in Python 2, so people who find it more readable and people still writing polyglot code would be able to use it, without the standard library unnecessarily providing two ways to do the exact same thing.

I'm now thinking a slight documentation improvement would have
addressed my own confusion (and I suspect the OPs as well):

* In the "Supported Operations" section of
change "Division (3) of t2 by t3." to "Division (3) of overall
duration t2 by interval unit t3."
* In the total_seconds() documentation, add a sentence "For interval
units other than seconds, use the division form directly (e.g. `td /


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list