[issue15443] datetime module has no support for nanoseconds

2012-07-25 Thread Vincenzo Ampolo

Vincenzo Ampolo vincenzo.amp...@gmail.com added the comment:

Have a look to this python dev mailing list thread too:

http://mail.python.org/pipermail/python-dev/2012-July/121123.html

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15443
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15443] datetime module has no support for nanoseconds

2012-07-24 Thread Vincenzo Ampolo

New submission from Vincenzo Ampolo vincenzo.amp...@gmail.com:

As long as computers evolve time management becomes more precise and more 
granular.
Unfortunately the standard datetime module is not able to deal with nanoseconds 
even if OSes are able to. For example if i do:

print %.9f % time.time()
1343158163.471209049

I've actual timestamp from the epoch with nanosecond granularity.

Thus support for nanoseconds in datetime would really be appreciated

--
components: ctypes
messages: 166326
nosy: Vincenzo.Ampolo
priority: normal
severity: normal
status: open
title: datetime module has no support for nanoseconds
type: enhancement
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15443
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15443] datetime module has no support for nanoseconds

2012-07-24 Thread Vincenzo Ampolo

Changes by Vincenzo Ampolo vincenzo.amp...@gmail.com:


--
components: +Library (Lib) -ctypes

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15443
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15443] datetime module has no support for nanoseconds

2012-07-24 Thread Vincenzo Ampolo

Vincenzo Ampolo vincenzo.amp...@gmail.com added the comment:

On 07/24/2012 01:28 PM, Marc-Andre Lemburg wrote:
 I would be interested in an actual use case for this.

Alice has a dataset with nanosecond granularity. He wants to make a
python library to let Bob access the dataset. Nowadays Alice has to
implement her own time class losing all the flexibility of the datetime
module. With this enhancement she can provide a library that just uses
the standard python datetime module. Her library will get the needed
time format, including nanoseconds.

Many python sql libraries, like the one in django e the one in web2py,
relay on datetime objects for time representation. Bob has a web2py
website that has some data with nanosecond granularity. Nowadays Bob has
to store this data as a string or a long number without the ability to
use the powerful datetime module. With this enhancement Bob doesn't need
to build or learn another interface, he can just use the datetime module
using microseconds or nanoseconds as needed.

Google search for python datetime nanoseconds shows more than 141k
results:
https://www.google.com/search?sourceid=chromeie=UTF-8q=python+time#hl=enbiw=1615bih=938sclient=psy-abq=python+datetime+nanosecondsoq=python+datetime+nanoseconds

So this is definitively a requested feature. And as soon as technology
evolves more people will ask for it.

I imagine something like:

import datetime
nano_time = datetime.datetime(year=2012, month=07, day=24, hour=14,
minute=35, second=3, microsecond=53, nanosecond=27)

in case you need nanosecond granularity. if you don't need it just skip
the nanosecond part and the module works like it's now. Of course
strftime format should be updated to support nanoseconds.

I can write a patch if some dev can maybe review it.

Before someone takes the datetime source code and starts a third part
module that supports nanoseconds, I think this enhancement has almost
null impact in existing code and makes the datetime module even more
powerful. It's up to the Cpython admins to decide between maintaining
datetime module up to date with new needs or let third part modules take
care of those lacks.

Best Regards,
-- 
Vincenzo Ampolo
http://vincenzo-ampolo.net
http://goshawknest.wordpress.com

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15443
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15443] datetime module has no support for nanoseconds

2012-07-24 Thread Vincenzo Ampolo

Vincenzo Ampolo vincenzo.amp...@gmail.com added the comment:

This is a real use case I'm working with that needs nanosecond precision
and lead me in submitting this request:

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.

Other case is in stock markets. In that field information is timed in
nanoseconds and have the ability to easily deal with this kind of
representation natively with datetime can make the standard module even
more powerful.

The company I work for is in the data networking field, and we use
python extensively. Currently we rely on custom code to process
timestamps, a nanosecond datetime would let us avoit that and use
standard python datetime module.

Best Regards,

---
Vincenzo Ampolo
http://vincenzo-ampolo.net
http://goshawknest.wordpress.com

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15443
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15443] datetime module has no support for nanoseconds

2012-07-24 Thread Vincenzo Ampolo

Changes by Vincenzo Ampolo vincenzo.amp...@gmail.com:


--
versions: +Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15443
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15443] datetime module has no support for nanoseconds

2012-07-24 Thread Vincenzo Ampolo

Vincenzo Ampolo vincenzo.amp...@gmail.com added the comment:

On 07/24/2012 04:20 PM, R. David Murray wrote:
 R. David Murray rdmur...@bitdance.com added the comment:
 
 Are the nanosecond timestamps timestamps or strings?  If they are timestamps 
 it's not immediately obvious why you want to convert them to datetime 
 objects, so motivating that would probably help.  On the other hand the fact 
 that you have an application that does so is certain an argument for real 
 world applicability.

It depends. When they are exported for example as csv (this can be the
case of market stock) or json (which is close to my case) that's a
string so having a datetime object may be very helpful in doing datetime
adds, subs, , deltas and in changing representation to human readable
format thanks to strftime() without loosing precison and maintaining
readability.

Think about a web application. User selects year, month, day, hour,
minute, millisecond, nanosecond of an event and the javascript does a
ajax call with time of this format (variant of iso8601):
-MM-DDTHH:MM:SS.mmnnn (where nnn is the nanosecond representation).
The python server takes that string, converts to a datetime, does all
the math with its data and gives the output back using labeling data
with int(nano_datetime.strftime('MMSSmmnnn')) so I've a sequence
number that javascript can sort and handle easily.

It's basically the same you already do nowadays at microseconds level,
but this time you have to deal with nanosecond data.

I agree with the YAGNI principle and I think that we have a clear
evidence of a real use case here indeed.

Best Regards

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15443
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com