diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2011-04-06 00:43:15 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2011-04-06 00:43:15 (GMT) |
commit | 28deea1fa56379f88f3a726c8145ec893c2040d5 (patch) | |
tree | e3072b2836cb3ed82fad4c55df91d596d458952f /Lib | |
parent | 3bd9729dc92ad3fc57aee17479231eb426fd076f (diff) | |
parent | b6f5ec737008f5c739ba3c667e1ae01b8625488b (diff) | |
download | cpython-28deea1fa56379f88f3a726c8145ec893c2040d5.zip cpython-28deea1fa56379f88f3a726c8145ec893c2040d5.tar.gz cpython-28deea1fa56379f88f3a726c8145ec893c2040d5.tar.bz2 |
Issue #11576: Fixed timedelta subtraction glitch on big timedelta values
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/datetime.py | 6 | ||||
-rw-r--r-- | Lib/test/datetimetester.py | 6 |
2 files changed, 11 insertions, 1 deletions
diff --git a/Lib/datetime.py b/Lib/datetime.py index 47e54ec..1ae7cb5 100644 --- a/Lib/datetime.py +++ b/Lib/datetime.py @@ -485,7 +485,11 @@ class timedelta: def __sub__(self, other): if isinstance(other, timedelta): - return self + -other + # for CPython compatibility, we cannot use + # our __class__ here, but need a real timedelta + return timedelta(self._days - other._days, + self._seconds - other._seconds, + self._microseconds - other._microseconds) return NotImplemented def __rsub__(self, other): diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index e9ceee6..38f3b8f 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -383,6 +383,12 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase): for i in range(-10, 10): eq((i*us/-3)//us, round(i/-3)) + # 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): a = timedelta(42) |