diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-25 23:02:32 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-25 23:02:32 (GMT) |
commit | be6859d877193004781c5b0b69f87b3ab5704ea1 (patch) | |
tree | 1a8448b965063fcea20203bfd949f215034155c0 /Modules | |
parent | 7d7aede558bc93196a40bd00fd857f57d00dd5bc (diff) | |
download | cpython-be6859d877193004781c5b0b69f87b3ab5704ea1.zip cpython-be6859d877193004781c5b0b69f87b3ab5704ea1.tar.gz cpython-be6859d877193004781c5b0b69f87b3ab5704ea1.tar.bz2 |
Merged revisions 76529 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76529 | antoine.pitrou | 2009-11-25 23:59:36 +0100 (mer., 25 nov. 2009) | 4 lines
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 8ba3474..764de34 100644 --- a/Modules/datetimemodule.c +++ b/Modules/datetimemodule.c @@ -2063,6 +2063,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)); @@ -2084,7 +2092,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}, |