Issue #5788: datetime.timedelta objects get a new total_seconds() method returning

the total number of seconds in the duration.  Patch by Brian Quinlan.
This commit is contained in:
Antoine Pitrou 2009-11-25 22:59:36 +00:00
parent 0d9f61a543
commit bcfaf8007d
4 changed files with 33 additions and 1 deletions

View file

@ -2088,6 +2088,14 @@ delta_getstate(PyDateTime_Delta *self)
GET_TD_MICROSECONDS(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)
{
@ -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},