[egenix-users] DateTimeFromString off by one sec?
M.-A. Lemburg
mal at egenix.com
Wed May 7 11:33:23 CEST 2008
On 2008-05-06 23:27, Francesco Pierfederici wrote:
> Hi,
>
> I am using mx.DateTime to parse dates and times in ISO format. I have
> noticed that DateTimeFromString seems to be off by one second if the
> time string being parsed ends with :59
>
>>>> mx.DateTime.Parser.DateTimeFromString('2008-05-06T19:30:09.59')
> <mx.DateTime.DateTime object for '2008-05-06 19:30:09.58' at 651a8>
>
> but
>
>>>> mx.DateTime.Parser.DateTimeFromString('2008-05-06T19:30:09.58')
> <mx.DateTime.DateTime object for '2008-05-06 19:30:09.58' at 8c250>
>
> Adding formats=['iso', ] does not change the results. I am using
> mx.DateTime 3.0 by the way.
>
>
> Am I doing something wrong?
It is not not off by a second, it's off by 1/100 of a second.
This looks a lot like a bug in the parser, since it starts to
parse the fraction with a 1/100 second offset starting at
x.59 onwards:
>>> DateTimeFrom('2008-05-06 19:30:09.57')
<mx.DateTime.DateTime object for '2008-05-06 19:30:09.57' at 2b1e3bdb08c8>
>>> DateTimeFrom('2008-05-06 19:30:09.58')
<mx.DateTime.DateTime object for '2008-05-06 19:30:09.58' at 2b1e3ba8bce8>
>>> DateTimeFrom('2008-05-06 19:30:09.59')
<mx.DateTime.DateTime object for '2008-05-06 19:30:09.58' at 2b1e3bdb08c8>
>>> DateTimeFrom('2008-05-06 19:30:09.60')
<mx.DateTime.DateTime object for '2008-05-06 19:30:09.59' at 2b1e3ba8bce8>
>>> DateTimeFrom('2008-05-06 19:30:09.61')
<mx.DateTime.DateTime object for '2008-05-06 19:30:09.60' at 2b1e3bdb08c8>
>>> DateTimeFrom('2008-05-06 19:30:09.62')
<mx.DateTime.DateTime object for '2008-05-06 19:30:09.61' at 2b1e3ba8bce8>
Note that it works again, if you use three decimal places:
>>> DateTimeFrom('2008-05-06 19:30:09.591')
<mx.DateTime.DateTime object for '2008-05-06 19:30:09.59' at 2b1e3bdb08c8>
>>> DateTimeFrom('2008-05-06 19:30:09.601')
<mx.DateTime.DateTime object for '2008-05-06 19:30:09.60' at 2b1e3bdb08c8>
However:
>>> DateTimeFrom('2008-05-06 19:30:09.590')
<mx.DateTime.DateTime object for '2008-05-06 19:30:09.58' at 2b1e3ba8bce8>
>>> DateTimeFrom('2008-05-06 19:30:09.600')
<mx.DateTime.DateTime object for '2008-05-06 19:30:09.59' at 2b1e3bdb08c8>
Weird bug :-)
I'll open a ticket for this.
Thank you for reporting this,
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, May 07 2008)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the egenix-users
mailing list