diff options
author | Federico Di Gregorio <fog@initd.org> | 2006-09-30 06:35:12 +0000 |
---|---|---|
committer | Federico Di Gregorio <fog@initd.org> | 2006-09-30 06:35:12 +0000 |
commit | 4820213b7f19fba656f84c73a2d999343c2ab3f8 (patch) | |
tree | 12d320ab40f2c553e9e5886ea2e42135de23a606 /psycopg/adapter_datetime.c | |
parent | bc580e33837f79f640fc603db328fb29851155fd (diff) | |
download | psycopg2-4820213b7f19fba656f84c73a2d999343c2ab3f8.tar.gz |
Fixed fractionary seconds >59 problem (closes: #131)
Diffstat (limited to 'psycopg/adapter_datetime.c')
-rw-r--r-- | psycopg/adapter_datetime.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c index 9129ca6..fa00011 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) { |