diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-25 22:59:36 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-25 22:59:36 (GMT) |
commit | bcfaf8007d8d14e3a6e65d13ad693b4874688cab (patch) | |
tree | 1423462840d4c68918760c667ad79f81e0c611ef /Modules | |
parent | 0d9f61a5437463c143a275a7b6bda257160dad76 (diff) | |
download | cpython-bcfaf8007d8d14e3a6e65d13ad693b4874688cab.zip cpython-bcfaf8007d8d14e3a6e65d13ad693b4874688cab.tar.gz cpython-bcfaf8007d8d14e3a6e65d13ad693b4874688cab.tar.bz2 |
Issue #5788: `datetime.timedelta` objects get a new `total_seconds()` method returning
the total number of seconds in the duration. Patch by Brian Quinlan.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/datetimemodule.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c index fcbd2e9..1818836 100644 --- a/Modules/datetimemodule.c +++ b/Modules/datetimemodule.c @@ -2089,6 +2089,14 @@ delta_getstate(PyDateTime_Delta *self) } static PyObject * +delta_total_seconds(PyObject *self) +{ + return PyFloat_FromDouble(GET_TD_MICROSECONDS(self) / 1000000.0 + + GET_TD_SECONDS(self) + + GET_TD_DAYS(self) * 24.0 * 3600.0); +} + +static PyObject * delta_reduce(PyDateTime_Delta* self) { return Py_BuildValue("ON", Py_TYPE(self), delta_getstate(self)); @@ -2110,7 +2118,10 @@ static PyMemberDef delta_members[] = { }; static PyMethodDef delta_methods[] = { - {"__reduce__", (PyCFunction)delta_reduce, METH_NOARGS, + {"total_seconds", (PyCFunction)delta_total_seconds, METH_NOARGS, + PyDoc_STR("Total seconds in the duration.")}, + + {"__reduce__", (PyCFunction)delta_reduce, METH_NOARGS, PyDoc_STR("__reduce__() -> (cls, state)")}, {NULL, NULL}, |