Ejemplo n.º 1
0
PyObject *
psyco_TimestampFromTicks(PyObject *self, PyObject *args)
{
    PyObject *m = NULL;
    PyObject *tz = NULL;
    PyObject *res = NULL;
    struct tm tm;
    time_t t;
    double ticks;

    if (!PyArg_ParseTuple(args, "d", &ticks))
        return NULL;

    /* get psycopg2.tz.LOCAL from pythonland */
    if (!(m = PyImport_ImportModule("psycopg2.tz"))) { goto exit; }
    if (!(tz = PyObject_GetAttrString(m, "LOCAL"))) { goto exit; }

    t = (time_t)floor(ticks);
    ticks -= (double)t;
    if (!localtime_r(&t, &tm)) {
        PyErr_SetString(InterfaceError, "failed localtime call");
        goto exit;
    }

    res = _psyco_Timestamp(
        tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
        tm.tm_hour, tm.tm_min, (double)tm.tm_sec + ticks,
        tz);

exit:
    Py_XDECREF(tz);
    Py_XDECREF(m);
    return res;
}
PyObject *
psyco_TimestampFromTicks(PyObject *self, PyObject *args)
{
    PyObject *res = NULL;
    struct tm tm;
    time_t t;
    double ticks;

    if (!PyArg_ParseTuple(args, "d", &ticks))
        return NULL;

    t = (time_t)floor(ticks);
    ticks -= (double)t;
    if (localtime_r(&t, &tm)) {
        res = _psyco_Timestamp(
            tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
            tm.tm_hour, tm.tm_min, (double)tm.tm_sec + ticks,
            pyPsycopgTzLOCAL);
    }
	else {
		PyErr_SetString(InterfaceError, "failed localtime call");
	}

    return res;
}
Ejemplo n.º 3
0
PyObject *
psyco_Timestamp(PyObject *self, PyObject *args)
{
    PyObject *tzinfo = NULL;
    int year, month, day;
    int hour=0, minute=0; /* default to midnight */
    double second=0.0;

    if (!PyArg_ParseTuple(args, "iii|iidO", &year, &month, &day,
                          &hour, &minute, &second, &tzinfo))
        return NULL;

    return _psyco_Timestamp(year, month, day, hour, minute, second, tzinfo);
}