mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Issue #11576: Fixed timedelta subtraction glitch on big timedelta values
This commit is contained in:
parent
04026cf56c
commit
b6f5ec7370
3 changed files with 19 additions and 8 deletions
|
@ -1801,13 +1801,14 @@ delta_subtract(PyObject *left, PyObject *right)
|
|||
|
||||
if (PyDelta_Check(left) && PyDelta_Check(right)) {
|
||||
/* delta - delta */
|
||||
PyObject *minus_right = PyNumber_Negative(right);
|
||||
if (minus_right) {
|
||||
result = delta_add(left, minus_right);
|
||||
Py_DECREF(minus_right);
|
||||
}
|
||||
else
|
||||
result = NULL;
|
||||
/* The C-level additions can't overflow because of the
|
||||
* invariant bounds.
|
||||
*/
|
||||
int days = GET_TD_DAYS(left) - GET_TD_DAYS(right);
|
||||
int seconds = GET_TD_SECONDS(left) - GET_TD_SECONDS(right);
|
||||
int microseconds = GET_TD_MICROSECONDS(left) -
|
||||
GET_TD_MICROSECONDS(right);
|
||||
result = new_delta(days, seconds, microseconds, 1);
|
||||
}
|
||||
|
||||
if (result == Py_NotImplemented)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue