diff options
author | Georg Brandl <georg@python.org> | 2010-07-31 11:40:07 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-07-31 11:40:07 (GMT) |
commit | f55c31594b9abb2ddb446d2d6206342a9258d205 (patch) | |
tree | 70c887b7eb8e35d6aac868053075c12a10e11dc5 | |
parent | a02607ea36dd9828c4dbb2b2d1dac305f88945ca (diff) | |
download | cpython-f55c31594b9abb2ddb446d2d6206342a9258d205.zip cpython-f55c31594b9abb2ddb446d2d6206342a9258d205.tar.gz cpython-f55c31594b9abb2ddb446d2d6206342a9258d205.tar.bz2 |
#9430: document timedelta str() and repr().
-rw-r--r-- | Doc/library/datetime.rst | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst index f626e35..22c82e8 100644 --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -265,6 +265,14 @@ Supported operations: | ``abs(t)`` | equivalent to +\ *t* when ``t.days >= 0``, and| | | to -*t* when ``t.days < 0``. (2) | +--------------------------------+-----------------------------------------------+ +| ``str(t)`` | Returns a string in the form | +| | ``[D day[s], ][H]H:MM:SS[.UUUUUU]``, where D | +| | is negative for negative ``t``. (5) | ++--------------------------------+-----------------------------------------------+ +| ``repr(t)`` | Returns a string in the form | +| | ``datetime.timedelta(D[, S[, U]])``, where D | +| | is negative for negative ``t``. (5) | ++--------------------------------+-----------------------------------------------+ Notes: @@ -280,6 +288,16 @@ Notes: (4) -*timedelta.max* is not representable as a :class:`timedelta` object. +(5) + String representations of :class:`timedelta` objects are normalized + similarly to their internal representation. This leads to somewhat + unusual results for negative timedeltas. For example: + + >>> timedelta(hours=-5) + datetime.timedelta(-1, 68400) + >>> print(_) + -1 day, 19:00:00 + In addition to the operations listed above :class:`timedelta` objects support certain additions and subtractions with :class:`date` and :class:`datetime` objects (see below). |