Fractionary seconds fix (closes: #130)

This commit is contained in:
Federico Di Gregorio 2006-09-30 06:16:24 +00:00
parent ca860424e6
commit 168d9c36af
2 changed files with 16 additions and 4 deletions

View File

@ -1,11 +1,17 @@
2006-09-30 Federico Di Gregorio <fog@initd.org>
* psycopg/adapter_datetime.py: now TimeFromTicks and
TimestampFromTicks both accept fractionary seconds (fixes #130).
2006-09-23 Federico Di Gregorio <fog@initd.org> 2006-09-23 Federico Di Gregorio <fog@initd.org>
* lib/errorcodes.py: added list of all PostgreSQL error codes * lib/errorcodes.py: added list of all PostgreSQL error codes
compiled by Johan Dahlin. compiled by Johan Dahlin.
* psycopg/psycopg.h: applied compatibility macros from PEP 353. * psycopg/psycopg.h: applied compatibility macros from PEP 353.
* Applied patch 1/3 from Piet Delport; from his email: * Applied patch 1/3 from Piet Delport; from his email:
psycopg2-Py_ssize_t-input.diff adjusts variables used for parameters psycopg2-Py_ssize_t-input.diff adjusts variables used for parameters
and return values. These changes only prevent overflowing on values and return values. These changes only prevent overflowing on values
greater than 32-bits, so they're not as critical as the other two greater than 32-bits, so they're not as critical as the other two
@ -14,13 +20,15 @@
either way, not being too familiar with the codebase. either way, not being too familiar with the codebase.
* Applied patch 2/3 from Piet Delport; from his email: * Applied patch 2/3 from Piet Delport; from his email:
psycopg2-Py_ssize_t-output.diff adjusts variables used as outputs psycopg2-Py_ssize_t-output.diff adjusts variables used as outputs
from CPython API calls: without it the calls try to write 64 bits from CPython API calls: without it the calls try to write 64 bits
to 32 bit locations, trampling over adjacent values/pointers, to 32 bit locations, trampling over adjacent values/pointers,
and segfaulting later. and segfaulting later.
* Applied patch 1/3 from Piet Delport; from his email: * Applied patch 1/3 from Piet Delport; from his email:
psycopg2-PyObject_HEAD.diff adds missing underscores to several
psycopg2-PyObject_HEAD.diff adds missing underscores to several
"PyObject_HEAD" declarations. As far as i can tell from gdb, the "PyObject_HEAD" declarations. As far as i can tell from gdb, the
"PyObject HEAD" versions end up accidentally meaning almost exactly "PyObject HEAD" versions end up accidentally meaning almost exactly
the same, but get aligned differently on AMD64, resulting in wrong the same, but get aligned differently on AMD64, resulting in wrong

View File

@ -375,8 +375,10 @@ psyco_TimeFromTicks(PyObject *self, PyObject *args)
return NULL; return NULL;
t = (time_t)round(ticks); t = (time_t)round(ticks);
ticks -= (double)t;
if (localtime_r(&t, &tm)) { if (localtime_r(&t, &tm)) {
args = Py_BuildValue("iid", tm.tm_hour, tm.tm_min, (double)tm.tm_sec); args = Py_BuildValue("iid", tm.tm_hour, tm.tm_min,
(double)tm.tm_sec + ticks);
if (args) { if (args) {
res = psyco_Time(self, args); res = psyco_Time(self, args);
Py_DECREF(args); Py_DECREF(args);
@ -397,10 +399,12 @@ psyco_TimestampFromTicks(PyObject *self, PyObject *args)
return NULL; return NULL;
t = (time_t)round(ticks); t = (time_t)round(ticks);
ticks -= (double)t;
if (localtime_r(&t, &tm)) { if (localtime_r(&t, &tm)) {
args = Py_BuildValue("iiiiidO", args = Py_BuildValue("iiiiidO",
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, (double)tm.tm_sec, tm.tm_hour, tm.tm_min,
(double)tm.tm_sec + ticks,
pyPsycopgTzLOCAL); pyPsycopgTzLOCAL);
if (args) { if (args) {
res = psyco_Timestamp(self, args); res = psyco_Timestamp(self, args);