[Python-Dev] datetime.timedelta total_microseconds

Henry Chen tahafut at gmail.com
Sat Feb 16 13:47:34 EST 2019


+1 on the improved docs solution: no new code to maintain and big return on
investment in preventing future bugs / confusion :)

On Sat, Feb 16, 2019 at 9:40 AM Nick Coghlan <ncoghlan at gmail.com> wrote:

> 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
> 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   |   ncoghlan at gmail.com   |   Brisbane, Australia
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/tahafut%40gmail.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20190216/48630dfa/attachment.html>


More information about the Python-Dev mailing list