On Sun, 17 Feb 2019 at 03:20, Paul Ganssle <p...@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 https://docs.python.org/3/library/datetime.html#timedelta-objects, 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 / timedelta(microseconds=1)`)" Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com