summaryrefslogtreecommitdiff
path: root/psycopg/adapter_datetime.c
diff options
context:
space:
mode:
Diffstat (limited to 'psycopg/adapter_datetime.c')
-rw-r--r--psycopg/adapter_datetime.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c
index 1afcb0c..024b712 100644
--- a/psycopg/adapter_datetime.c
+++ b/psycopg/adapter_datetime.c
@@ -43,6 +43,9 @@ extern PyObject *pyTimeTypeP;
extern PyObject *pyDateTimeTypeP;
extern PyObject *pyDeltaTypeP;
+extern PyObject *pyPsycopgTzModule;
+extern PyObject *pyPsycopgTzLocalTimezone;
+
/* datetime_str, datetime_getquoted - return result of quoting */
static PyObject *
@@ -275,18 +278,24 @@ PyObject *
psyco_Time(PyObject *self, PyObject *args)
{
PyObject *res = NULL;
+ PyObject *tzinfo = NULL;
int hours, minutes=0;
double micro, seconds=0.0;
PyObject* obj = NULL;
- if (!PyArg_ParseTuple(args, "iid", &hours, &minutes, &seconds))
+ if (!PyArg_ParseTuple(args, "iid|O", &hours, &minutes, &seconds,
+ &tzinfo))
return NULL;
micro = (seconds - floor(seconds)) * 1000000.0;
- obj = PyObject_CallFunction(pyTimeTypeP, "iiii",
- hours, minutes, (int)round(seconds), (int)round(micro));
+ if (tzinfo == NULL)
+ obj = PyObject_CallFunction(pyTimeTypeP, "iiii",
+ hours, minutes, (int)round(seconds), (int)round(micro));
+ else
+ obj = PyObject_CallFunction(pyTimeTypeP, "iiiiO",
+ hours, minutes, (int)round(seconds), (int)round(micro), tzinfo);
if (obj) {
res = PyObject_CallFunction((PyObject *)&pydatetimeType,
@@ -301,21 +310,28 @@ PyObject *
psyco_Timestamp(PyObject *self, PyObject *args)
{
PyObject *res = NULL;
+ PyObject *tzinfo = NULL;
int year, month, day;
int hour=0, minute=0; /* default to midnight */
double micro, second=0.0;
PyObject* obj = NULL;
- if (!PyArg_ParseTuple(args, "lii|iid", &year, &month, &day,
- &hour, &minute, &second))
+ if (!PyArg_ParseTuple(args, "lii|iidO", &year, &month, &day,
+ &hour, &minute, &second, &tzinfo))
return NULL;
micro = (second - floor(second)) * 1000000.0;
- obj = PyObject_CallFunction(pyDateTimeTypeP, "iiiiiii",
- year, month, day, hour, minute, (int)round(second), (int)round(micro));
-
+ if (tzinfo == NULL)
+ obj = PyObject_CallFunction(pyDateTimeTypeP, "iiiiiii",
+ year, month, day, hour, minute, (int)round(second),
+ (int)round(micro));
+ else
+ obj = PyObject_CallFunction(pyDateTimeTypeP, "iiiiiiiO",
+ year, month, day, hour, minute, (int)round(second),
+ (int)round(micro), tzinfo);
+
if (obj) {
res = PyObject_CallFunction((PyObject *)&pydatetimeType,
"Oi", obj, PSYCO_DATETIME_TIMESTAMP);
@@ -337,7 +353,7 @@ psyco_DateFromTicks(PyObject *self, PyObject *args)
return NULL;
t = (time_t)round(ticks);
- if (gmtime_r(&t, &tm)) {
+ if (localtime_r(&t, &tm)) {
args = Py_BuildValue("iii", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
if (args) {
res = psyco_Date(self, args);
@@ -359,7 +375,7 @@ psyco_TimeFromTicks(PyObject *self, PyObject *args)
return NULL;
t = (time_t)round(ticks);
- if (gmtime_r(&t, &tm)) {
+ if (localtime_r(&t, &tm)) {
args = Py_BuildValue("iid", tm.tm_hour, tm.tm_min, (double)tm.tm_sec);
if (args) {
res = psyco_Time(self, args);
@@ -381,10 +397,11 @@ psyco_TimestampFromTicks(PyObject *self, PyObject *args)
return NULL;
t = (time_t)round(ticks);
- if (gmtime_r(&t, &tm)) {
- args = Py_BuildValue("iiiiid",
+ if (localtime_r(&t, &tm)) {
+ args = Py_BuildValue("iiiiidO",
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,
+ pyPsycopgTzLocalTimezone);
if (args) {
res = psyco_Timestamp(self, args);
Py_DECREF(args);