static PyObject * time_ctime(PyObject *self, PyObject *args) { PyObject *ot = NULL; time_t tt; char *p; if (!PyArg_UnpackTuple(args, "ctime", 0, 1, &ot)) return NULL; if (ot == NULL || ot == Py_None) tt = time(NULL); else { double dt = PyFloat_AsDouble(ot); if (PyErr_Occurred()) return NULL; tt = _PyTime_DoubleToTimet(dt); if (tt == (time_t)-1 && PyErr_Occurred()) return NULL; } p = ctime(&tt); if (p == NULL) { PyErr_SetString(PyExc_ValueError, "unconvertible time"); return NULL; } if (p[24] == '\n') p[24] = '\0'; return PyString_FromString(p); }
static PyObject * time_ctime(PyObject *self, PyObject *args) { PyObject *ot = NULL; time_t tt; struct tm *timeptr; if (!PyArg_UnpackTuple(args, "ctime", 0, 1, &ot)) return NULL; if (ot == NULL || ot == Py_None) tt = time(NULL); else { double dt = PyFloat_AsDouble(ot); if (PyErr_Occurred()) return NULL; tt = _PyTime_DoubleToTimet(dt); if (tt == (time_t)-1 && PyErr_Occurred()) return NULL; } timeptr = localtime(&tt); if (timeptr == NULL) { PyErr_SetString(PyExc_ValueError, "unconvertible time"); return NULL; } return _asctime(timeptr); }
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); }