diff --git a/ChangeLog b/ChangeLog index 4a31b9bd..c80c6a7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-09-30 Federico Di Gregorio + * psycopg/adapter_datetime.py: fixed conversion problem with seconds + in the (59,60) range (fixes #131). + * ZpsycopgDA/DA.py: we now split on GMT+, GMT-, + or -. This should fix bug #129. diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c index 9129ca68..fa00011f 100644 --- a/psycopg/adapter_datetime.c +++ b/psycopg/adapter_datetime.c @@ -277,25 +277,26 @@ psyco_Date(PyObject *self, PyObject *args) PyObject * psyco_Time(PyObject *self, PyObject *args) { - PyObject *res = NULL; + PyObject *res = NULL; PyObject *tzinfo = NULL; int hours, minutes=0; - double micro, seconds=0.0; + double micro, second=0.0; PyObject* obj = NULL; - if (!PyArg_ParseTuple(args, "iid|O", &hours, &minutes, &seconds, + if (!PyArg_ParseTuple(args, "iid|O", &hours, &minutes, &second, &tzinfo)) return NULL; - micro = (seconds - floor(seconds)) * 1000000.0; - + micro = (second - floor(second)) * 1000000.0; + second = floor(second); + if (tzinfo == NULL) obj = PyObject_CallFunction(pyTimeTypeP, "iiii", - hours, minutes, (int)round(seconds), (int)round(micro)); + hours, minutes, (int)second, (int)round(micro)); else obj = PyObject_CallFunction(pyTimeTypeP, "iiiiO", - hours, minutes, (int)round(seconds), (int)round(micro), tzinfo); + hours, minutes, (int)second, (int)round(micro), tzinfo); if (obj) { res = PyObject_CallFunction((PyObject *)&pydatetimeType, @@ -309,11 +310,11 @@ psyco_Time(PyObject *self, PyObject *args) PyObject * psyco_Timestamp(PyObject *self, PyObject *args) { - PyObject *res = NULL; + PyObject *res = NULL; PyObject *tzinfo = NULL; int year, month, day; - int hour=0, minute=0; /* default to midnight */ - double micro, second=0.0; + int hour=0, minute=0; /* default to midnight */ + double micro, second=0.0; PyObject* obj = NULL; @@ -322,14 +323,15 @@ psyco_Timestamp(PyObject *self, PyObject *args) return NULL; micro = (second - floor(second)) * 1000000.0; - + second = floor(second); + if (tzinfo == NULL) obj = PyObject_CallFunction(pyDateTimeTypeP, "iiiiiii", - year, month, day, hour, minute, (int)round(second), + year, month, day, hour, minute, (int)second, (int)round(micro)); else obj = PyObject_CallFunction(pyDateTimeTypeP, "iiiiiiiO", - year, month, day, hour, minute, (int)round(second), + year, month, day, hour, minute, (int)second, (int)round(micro), tzinfo); if (obj) {