Fixed problem with locales in mx.DateTime adaptation.

This commit is contained in:
Federico Di Gregorio 2007-01-16 10:47:28 +00:00
parent b651781f63
commit d342d37e27
2 changed files with 16 additions and 13 deletions

View File

@ -1,5 +1,9 @@
2007-01-16 Federico Di Gregorio <fog@initd.org> 2007-01-16 Federico Di Gregorio <fog@initd.org>
* psycopg/adapt_mxdatetime.c: fixed #137 by accessing the 'date' and
'time' attributes of the mx.DateTime instance: they are always in ISO
format.
* psycopg/typecast_datetime.c: fixed problem with year > 9999. * psycopg/typecast_datetime.c: fixed problem with year > 9999.
2006-10-29 Federico Di Gregorio <fog@initd.org> 2006-10-29 Federico Di Gregorio <fog@initd.org>

View File

@ -43,23 +43,22 @@ static PyObject *
mxdatetime_str(mxdatetimeObject *self) mxdatetime_str(mxdatetimeObject *self)
{ {
PyObject *str = NULL, *res = NULL; PyObject *str = NULL, *res = NULL;
PyObject *supa, *supb;
switch (self->type) { switch (self->type) {
case PSYCO_MXDATETIME_DATE: case PSYCO_MXDATETIME_DATE:
case PSYCO_MXDATETIME_TIMESTAMP: str = PyObject_GetAttrString(self->wrapped, "date");
str = PyObject_Str(self->wrapped); break;
/* given the limitation of the mx.DateTime module that uses the same case PSYCO_MXDATETIME_TIMESTAMP:
type for both date and timestamp values we need to do some black /* here we build the right ISO string from date and time */
magic and make sure we're not using an adapt()ed timestamp as a supa = PyObject_GetAttrString(self->wrapped, "date");
simple date */ supb = PyObject_GetAttrString(self->wrapped, "time");
if (strncmp(&(PyString_AsString(str)[11]), "00:00:00.000", 12) == 0) { str = PyString_FromFormat("%sT%s",
PyObject *tmp = PyString_AsString(supa), PyString_AsString(supb));
PyString_FromStringAndSize(PyString_AsString(str), 10); Py_XDECREF(supa);
Py_DECREF(str); Py_XDECREF(supb);
str = tmp;
}
break; break;
case PSYCO_MXDATETIME_TIME: case PSYCO_MXDATETIME_TIME: