summaryrefslogtreecommitdiffstats
path: root/Doc/library/datetime.rst
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-04-20 22:32:49 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-04-20 22:32:49 (GMT)
commit7c186e2a18bf174afd5cccc8c35b7167d05f7e2a (patch)
tree1ba75e9cb85d4ab1e0320d3636c1db90d5c8f97e /Doc/library/datetime.rst
parent50eb60e6bfedbdad2dda30fa5ce7fe3ce83f7748 (diff)
downloadcpython-7c186e2a18bf174afd5cccc8c35b7167d05f7e2a.zip
cpython-7c186e2a18bf174afd5cccc8c35b7167d05f7e2a.tar.gz
cpython-7c186e2a18bf174afd5cccc8c35b7167d05f7e2a.tar.bz2
Issue #2706: Add support for dividing a timedelta by another timedelta.
Adds support for the three division operations: - timedelta / timedelta -> float - timedelta // timedelta -> int - timedelta % timedelta -> timedelta also adds support for divmod(timedelta, timedelta). Patch by Victor Stinner, adapted for py3k and extended by Alexander Belopolsky.
Diffstat (limited to 'Doc/library/datetime.rst')
-rw-r--r--Doc/library/datetime.rst22
1 files changed, 20 insertions, 2 deletions
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 65122f2..758e4d2 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -220,8 +220,20 @@ Supported operations:
| | In general, *t1* \* i == *t1* \* (i-1) + *t1* |
| | is true. (1) |
+--------------------------------+-----------------------------------------------+
-| ``t1 = t2 // i`` | The floor is computed and the remainder (if |
-| | any) is thrown away. (3) |
+| ``f = t2 / t3`` | Division (3) of *t2* by *t3*. Returns a |
+| | :class:`float` object. |
++--------------------------------+-----------------------------------------------+
+| ``t1 = t2 // i`` or | The floor is computed and the remainder (if |
+| ``t1 = t2 // t3`` | any) is thrown away. In the second case, an |
+| | integer is returned (3) |
++--------------------------------+-----------------------------------------------+
+| ``t1 = t2 % t3`` | The remainder is computed as a |
+| | :class:`timedelta` object. (3) |
++--------------------------------+-----------------------------------------------+
+| ``q, r = divmod(t1, t2)`` | Computes the quotient and the remainder: |
+| | ``q = t1 // t2`` (3) and ``r = t1 % t2``. |
+| | q is an integer and r is a :class:`timedelta` |
+| | object. |
+--------------------------------+-----------------------------------------------+
| ``+t1`` | Returns a :class:`timedelta` object with the |
| | same value. (2) |
@@ -252,6 +264,12 @@ In addition to the operations listed above :class:`timedelta` objects support
certain additions and subtractions with :class:`date` and :class:`datetime`
objects (see below).
+.. versionadded:: 3.2
+ Floor division and true division of a :class:`timedelta` object by
+ another :class:`timedelta` object are now supported, as are
+ remainder operations and the :func:`divmod` function.
+
+
Comparisons of :class:`timedelta` objects are supported with the
:class:`timedelta` object representing the smaller duration considered to be the
smaller timedelta. In order to stop mixed-type comparisons from falling back to