Index: Modules/datetimemodule.c =================================================================== --- Modules/datetimemodule.c (révision 67177) +++ Modules/datetimemodule.c (copie de travail) @@ -4527,6 +4527,37 @@ return build_struct_time(y, m, d, hh, mm, ss, 0); } +static PyObject * +datetime_totimestamp(PyObject *self) +{ + PyObject *timetuple, *time; + PyObject *timet, *us, *timestamp; + + /* create the time tuple */ + timetuple = datetime_timetuple((PyDateTime_DateTime *)self); + if (timetuple == NULL) + return NULL; + + /* call time.mktime(tuple) */ + time = PyImport_ImportModuleNoBlock("time"); + if (time == NULL) + return NULL; + timet = PyObject_CallMethod(time, "mktime", "O", timetuple); + Py_DECREF(timetuple); + Py_DECREF(time); + if (timet == NULL) + return NULL; + + /* add microseconds / 1e6 */ + us = PyFloat_FromDouble(DATE_GET_MICROSECOND(self) * 1e-6); + timestamp = PyNumber_Add(timet, us); + Py_DECREF(timet); + Py_DECREF(us); + + return timestamp; +} + + /* Pickle support, a simple use of __reduce__. */ /* Let basestate be the non-tzinfo data string. @@ -4579,6 +4610,11 @@ PyDoc_STR("timestamp -> UTC datetime from a POSIX timestamp " "(like time.time()).")}, + {"totimestamp", (PyCFunction)datetime_totimestamp, + METH_NOARGS, + PyDoc_STR("Return a local POSIX timestamp:\n" + "time.mktime(t.timetuple()) + t.microsecond/1e6")}, + {"strptime", (PyCFunction)datetime_strptime, METH_VARARGS | METH_CLASS, PyDoc_STR("string, format -> new datetime parsed from a string "