|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Missing microseconds in datetime objects [with patch]Hey all,
The company I worked for needed subsecond accuracy on datetime objects, but microseconds were getting lost in translation. To demonstrate, I used the CherryPy echo server and the following client: ----- Begin Client ----- #!/usr/bin/env python from datetime import datetime from pyamf.remoting.client import RemotingService gw = RemotingService('http://localhost:8080/gateway/') service = gw.getService('myservice') dt = datetime.now() print 'in:', dt print 'out:', service.echo(dt) ----- End Client ----- $ python test-client.py in: 2009-03-06 18:46:36.913483 out: 2009-03-06 18:46:36 Turns out, timetuples don't hold microseconds and we need to add them manually: ----- Begin diff ----- Index: util/__init__.py =================================================================== --- util/__init__.py (revision 2229) +++ util/__init__.py (working copy) @@ -634,7 +634,8 @@ if isinstance(d, datetime.date) and not isinstance(d, datetime.datetime): d = datetime.datetime.combine(d, datetime.time(0, 0, 0, 0)) - return calendar.timegm(d.utctimetuple()) + msec = str(d.microsecond).rjust(6, '0') + return float('%s.%s' % (calendar.timegm(d.utctimetuple()), msec)) def get_datetime(secs): """ ----- End diff ----- $ python test-client.py in: 2009-03-06 18:48:33.054154 out: 2009-03-06 18:48:33.054154 I patched this internally months ago, sorry for only just now getting it out to the list. --Derek _______________________________________________ PyAMF dev mailing list - dev@... http://lists.pyamf.org/mailman/listinfo/dev |
|
|
Re: Missing microseconds in datetime objects [with patch]Thanks for the report and patch Derek, I verified the fix and opened a ticket for it:
Cheers, Thijs On 7 Mar 2009, at 03:32, Derek Payton wrote: Hey all, _______________________________________________ PyAMF dev mailing list - dev@... http://lists.pyamf.org/mailman/listinfo/dev |
| Free embeddable forum powered by Nabble | Forum Help |