mirror of
https://github.com/python/cpython.git
synced 2025-11-08 13:42:22 +00:00
Issue #11576: Fixed timedelta subtraction glitch on big timedelta values
This commit is contained in:
parent
5f511826c2
commit
07019bcaab
2 changed files with 15 additions and 7 deletions
|
|
@ -231,6 +231,13 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
|
||||||
eq(a//10, td(0, 7*24*360))
|
eq(a//10, td(0, 7*24*360))
|
||||||
eq(a//3600000, td(0, 0, 7*24*1000))
|
eq(a//3600000, td(0, 0, 7*24*1000))
|
||||||
|
|
||||||
|
# Issue #11576
|
||||||
|
eq(td(999999999, 86399, 999999) - td(999999999, 86399, 999998),
|
||||||
|
td(0, 0, 1))
|
||||||
|
eq(td(999999999, 1, 1) - td(999999999, 1, 0),
|
||||||
|
td(0, 0, 1))
|
||||||
|
|
||||||
|
|
||||||
def test_disallowed_computations(self):
|
def test_disallowed_computations(self):
|
||||||
a = timedelta(42)
|
a = timedelta(42)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1737,13 +1737,14 @@ delta_subtract(PyObject *left, PyObject *right)
|
||||||
|
|
||||||
if (PyDelta_Check(left) && PyDelta_Check(right)) {
|
if (PyDelta_Check(left) && PyDelta_Check(right)) {
|
||||||
/* delta - delta */
|
/* delta - delta */
|
||||||
PyObject *minus_right = PyNumber_Negative(right);
|
/* The C-level additions can't overflow because of the
|
||||||
if (minus_right) {
|
* invariant bounds.
|
||||||
result = delta_add(left, minus_right);
|
*/
|
||||||
Py_DECREF(minus_right);
|
int days = GET_TD_DAYS(left) - GET_TD_DAYS(right);
|
||||||
}
|
int seconds = GET_TD_SECONDS(left) - GET_TD_SECONDS(right);
|
||||||
else
|
int microseconds = GET_TD_MICROSECONDS(left) -
|
||||||
result = NULL;
|
GET_TD_MICROSECONDS(right);
|
||||||
|
result = new_delta(days, seconds, microseconds, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == Py_NotImplemented)
|
if (result == Py_NotImplemented)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue