5 Dec 2002 02:21
Re: Why does TimestampFromMx chop off the milliseconds?
Chris Douty <Chris_Douty@...>
Re: Why does TimestampFromMx chop off the milliseconds?
2002-12-05 01:21:45 GMT
Re: Why does TimestampFromMx chop off the milliseconds?
2002-12-05 01:21:45 GMT
Hi all, I know it's bad form to respond to yourself, but I figured out why psycopg.TimestampFromMX() chops off the fractional seconds. Internally the strftime method of mx.DateTime objects is used, and the strftime function has no way to specify fractional seconds in the output. Additionally, the struct tm data type only uses an integer number of seconds. I was able to successfully use str() on my DateTime objects to get a full timestamp like I wanted. Now I am fighting a different battle. Sometimes the original mx.DateTime object I inserted and the one retrieved from the database do not match. I think that it probably has something to do with floating point rounding errors. For example. >>> t1 = DateTime(2002,12,4,14,27,2.170) >>> str(t1) '2002-12-02 16:27:02.16' >>> t1.absvalues() (731186, 59222.169999999998) >>> 2+170/1000.0 # Which is how I calculate seconds for the DateTime constructor 2.1699999999999999 I think that the problem is that str() on a DateTime object truncates the seconds value at 2 digits, and there's no way I've fond to get it to give more precision or round correctly. O suppose that I could make my own version of strftime that does what I want in python. Gah. Cheers, Chris On Wednesday, December 4, 2002, at 01:38 PM, Chris Douty wrote: > Why, oh why, do the various Time* functions in psycopg ignore > fractional seconds? > > I really need to preserve fractional seconds. I just noticed that all > of my timestamps were truncated by psycopg. I can see two potential > workarounds, use the str() function on my mx.DateTime object and > insert the string. The other option is to fix the source to psycopg > so that these functions don't truncate my timestamps. I guess that's > not really a workaround, that open source.> > What really has me perplexed is that psycopg properly retains the > fractional seconds when converting > a database timestamp field into a mx.DateTime object. WTF? -- -- Christopher Douty <Chris_Douty@...> +1-650-367-3129 Senior Engineer, Software & Systems - AMPEX Data Systems Corp.
>
> What really has me perplexed is that psycopg properly retains the
> fractional seconds when converting
> a database timestamp field into a mx.DateTime object. WTF?
RSS Feed