Interval conversion fix.

This commit is contained in:
Federico Di Gregorio 2006-07-26 05:13:08 +00:00
parent b9fcde1b39
commit b9f7c24a63
2 changed files with 11 additions and 6 deletions

View File

@ -1,3 +1,9 @@
2006-07-26 Federico Di Gregorio <fog@initd.org>
* psycopg/adapter_datetime.c (pydatetime_str): fixed error
in conversion of microseconds for intervals and better algo
(thanks to Mario Frasca.)
2006-06-18 Federico Di Gregorio <fog@initd.org> 2006-06-18 Federico Di Gregorio <fog@initd.org>
* psycopg/adapter_binary.c: same as below. * psycopg/adapter_binary.c: same as below.

View File

@ -64,15 +64,14 @@ pydatetime_str(pydatetimeObject *self)
PyDateTime_Delta *obj = (PyDateTime_Delta*)self->wrapped; PyDateTime_Delta *obj = (PyDateTime_Delta*)self->wrapped;
char buffer[8]; char buffer[8];
int i, j, x; int i;
int a = obj->microseconds; int a = obj->microseconds;
for (i=1000000, j=0; i > 0 ; i /= 10) { for (i=0; i < 6 ; i++) {
x = a/i; buffer[5-i] = '0' + (a % 10);
a -= x*i; a /= 10;
buffer[j++] = '0'+x;
} }
buffer[j] = '\0'; buffer[6] = '\0';
return PyString_FromFormat("'%d days %d.%s seconds'", return PyString_FromFormat("'%d days %d.%s seconds'",
obj->days, obj->seconds, buffer); obj->days, obj->seconds, buffer);