Example #1
0
static PyObject *
time_gmtime(PyObject *self, PyObject *args)
{
    time_t when;
    struct tm buf;

    if (!parse_time_t_args(args, "|O:gmtime", &when))
        return NULL;

    errno = 0;
    if (_PyTime_gmtime(when, &buf) != 0)
        return NULL;
#ifdef HAVE_STRUCT_TM_TM_ZONE
    return tmtotuple(&buf);
#else
    return tmtotuple(&buf, "UTC", 0);
#endif
}
Example #2
0
static PyObject *
time_localtime(PyObject *self, PyObject *args)
{
    time_t when;
    struct tm buf;

    if (!parse_time_t_args(args, "|O:localtime", &when))
        return NULL;
    if (pylocaltime(&when, &buf) == -1)
        return NULL;
    return tmtotuple(&buf);
}
Example #3
0
static PyObject *
time_localtime(PyObject *self, PyObject *args)
{
    time_t when;
    struct tm buf;

    if (!parse_time_t_args(args, "|O:localtime", &when))
        return NULL;
    if (_PyTime_localtime(when, &buf) != 0)
        return NULL;
#ifdef HAVE_STRUCT_TM_TM_ZONE
    return tmtotuple(&buf);
#else
    {
        struct tm local = buf;
        char zone[100];
        int gmtoff;
        strftime(zone, sizeof(zone), "%Z", &buf);
        gmtoff = timegm(&buf) - when;
        return tmtotuple(&local, zone, gmtoff);
    }
#endif
}
Example #4
0
static PyObject *
time_convert(time_t when, struct tm * (*function)(const time_t *))
{
	struct tm *p;
	errno = 0;
	p = function(&when);
	if (p == NULL) {
#ifdef EINVAL
		if (errno == 0)
			errno = EINVAL;
#endif
		return PyErr_SetFromErrno(PyExc_ValueError);
	}
	return tmtotuple(p);
}
Example #5
0
static PyObject *
time_convert(double when, struct tm * (*function)(const time_t *))
{
	struct tm *p;
	time_t whent = _PyTime_DoubleToTimet(when);

	if (whent == (time_t)-1 && PyErr_Occurred())
		return NULL;
	errno = 0;
	p = function(&whent);
	if (p == NULL) {
#ifdef EINVAL
		if (errno == 0)
			errno = EINVAL;
#endif
		return PyErr_SetFromErrno(PyExc_ValueError);
	}
	return tmtotuple(p);
}
Example #6
0
static PyObject *
time_gmtime(PyObject *self, PyObject *args)
{
    time_t when;
    struct tm buf, *local;

    if (!parse_time_t_args(args, "|O:gmtime", &when))
        return NULL;

    errno = 0;
    local = gmtime(&when);
    if (local == NULL) {
#ifdef EINVAL
        if (errno == 0)
            errno = EINVAL;
#endif
        return PyErr_SetFromErrno(PyExc_OSError);
    }
    buf = *local;
    return tmtotuple(&buf);
}