[Python-Dev] datetime.timedelta total_microseconds

Rob Cliffe rob.cliffe at btinternet.com
Fri Feb 15 14:44:39 EST 2019


A function with "microseconds" in the name IMO misleadingly suggests 
that it has something closer to microsecond accuracy than a 1-second 
granularity.
Rob Cliffe

On 14/02/2019 05:05:54, Richard Belleville via Python-Dev wrote:
> In a recent code review, the following snippet was called out as 
> reinventing the
> wheel:
>
> _MICROSECONDS_PER_SECOND = 1000000
>
>
> def _timedelta_to_microseconds(delta):
>   return int(delta.total_seconds() * _MICROSECONDS_PER_SECOND)
>
>
> The reviewer thought that there must already exist a standard library 
> function
> that fulfills this functionality. After we had both satisfied 
> ourselves that we
> hadn't simply missed something in the documentation, we decided that 
> we had
> better raise the issue with a wider audience.
>
> Does this functionality already exist within the standard library? If 
> not, would
> a datetime.timedelta.total_microseconds function be a reasonable 
> addition? I
> would be happy to submit a patch for such a thing.
>
> Richard Belleville
>
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> 
> 	Virus-free. www.avg.com 
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> 
>
>
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> _______________________________________________
> 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/rob.cliffe%40btinternet.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20190215/79582420/attachment.html>


More information about the Python-Dev mailing list