Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b6e49a

Browse files
farhaanbukhshabalkin
authored andcommitted
bpo-30516: Fix documentation issue with -timedelta in datetime (GH-7348)
This commit fixes the -timedelta overfllow issue not documented properly. Signed-off-by: Farhaan Bukhsh <[email protected]>
1 parent a390cb6 commit 5b6e49a

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Doc/library/datetime.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ Supported operations:
241241
+--------------------------------+-----------------------------------------------+
242242
| ``t1 = t2 - t3`` | Difference of *t2* and *t3*. Afterwards *t1* |
243243
| | == *t2* - *t3* and *t2* == *t1* + *t3* are |
244-
| | true. (1) |
244+
| | true. (1)(6) |
245245
+--------------------------------+-----------------------------------------------+
246246
| ``t1 = t2 * i or t1 = i * t2`` | Delta multiplied by an integer. |
247247
| | Afterwards *t1* // i == *t2* is true, |
@@ -317,6 +317,11 @@ Notes:
317317
>>> print(_)
318318
-1 day, 19:00:00
319319

320+
(6)
321+
The expression ``t2 - t3`` will always be equal to the expression ``t2 + (-t3)`` except
322+
when t3 is equal to ``timedelta.max``; in that case the former will produce a result
323+
while the latter will overflow.
324+
320325
In addition to the operations listed above :class:`timedelta` objects support
321326
certain additions and subtractions with :class:`date` and :class:`.datetime`
322327
objects (see below).
@@ -513,8 +518,6 @@ Notes:
513518
:const:`MINYEAR` or larger than :const:`MAXYEAR`.
514519

515520
(2)
516-
This isn't quite equivalent to date1 + (-timedelta), because -timedelta in
517-
isolation can overflow in cases where date1 - timedelta does not.
518521
``timedelta.seconds`` and ``timedelta.microseconds`` are ignored.
519522

520523
(3)
@@ -961,8 +964,6 @@ Supported operations:
961964
Computes the datetime2 such that datetime2 + timedelta == datetime1. As for
962965
addition, the result has the same :attr:`~.datetime.tzinfo` attribute as the input
963966
datetime, and no time zone adjustments are done even if the input is aware.
964-
This isn't quite equivalent to datetime1 + (-timedelta), because -timedelta
965-
in isolation can overflow in cases where datetime1 - timedelta does not.
966967

967968
(3)
968969
Subtraction of a :class:`.datetime` from a :class:`.datetime` is defined only if

0 commit comments

Comments
 (0)