[Python-Dev] datetime nanosecond support
Guido van Rossum
guido at python.org
Wed Jul 25 03:46:43 CEST 2012
On Tue, Jul 24, 2012 at 5:58 PM, Vincenzo Ampolo
<vincenzo.ampolo at gmail.com> wrote:
> Hi all,
> This is the first time I write to this list so thank you for considering
> this message (if you will) :)
> I know that this has been debated many times but until now there was no
> a real use case. If you look on google about "python datetime
> nanosecond" you can find more than 141k answer about that. They all say
> that "you can't due to hardware imprecisions" or "you don't need it"
> even if there is a good amount of people looking for this feature.
Have you read PEP 410 and my rejection of it
Even though that's about using Decimal for timestamps, it could still
be considered related.
> But let me explain my use case:
> most OSes let users capture network packets (using tools like tcpdump or
> wireshark) and store them using file formats like pcap or pcap-ng. These
> formats include a timestamp for each of the captured packets, and this
> timestamp usually has nanosecond precision. The reason is that on
> gigabit and 10 gigabit networks the frame rate is so high that
> microsecond precision is not enough to tell two frames apart.
> pcap (and now pcap-ng) are extremely popular file formats, with millions
> of files stored around the world. Support for nanoseconds in datetime
> would make it possible to properly parse these files inside python to
> compute precise statistics, for example network delays or round trip times.
> More about this issue at http://bugs.python.org/issue15443
> I completely agree with the YAGNI principle that seems to have driven
> decisions in this area until now but It is the case to reconsider it
> since this real use case has shown up?
Not every use case deserves an API change. :-)
First you will have to show how you'd have to code this *without*
nanosecond precision in datetime and how tedious that is. (I expect
that representing the timestamp as a long integer expressing a posix
timestamp times a billion would be very reasonable.)
I didn't read the entire bug, but it mentioned something about storing
datetimes in databases. Do databases support nanosecond precision?
--Guido van Rossum (python.org/~guido)
More information about the Python-Dev