diff --git a/ChangeLog b/ChangeLog index 6497f4e7..8b99c354 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-07-26 Federico Di Gregorio + + * 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 * psycopg/adapter_binary.c: same as below. diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c index 50796387..6409ceff 100644 --- a/psycopg/adapter_datetime.c +++ b/psycopg/adapter_datetime.c @@ -64,15 +64,14 @@ pydatetime_str(pydatetimeObject *self) PyDateTime_Delta *obj = (PyDateTime_Delta*)self->wrapped; char buffer[8]; - int i, j, x; + int i; int a = obj->microseconds; - for (i=1000000, j=0; i > 0 ; i /= 10) { - x = a/i; - a -= x*i; - buffer[j++] = '0'+x; + for (i=0; i < 6 ; i++) { + buffer[5-i] = '0' + (a % 10); + a /= 10; } - buffer[j] = '\0'; + buffer[6] = '\0'; return PyString_FromFormat("'%d days %d.%s seconds'", obj->days, obj->seconds, buffer);