![](https://secure.gravatar.com/avatar/8ac615df352a970211b0e3d94a307c6d.jpg?s=120&d=mm&r=g)
Author: georg.brandl Date: Sat Jul 31 13:40:07 2010 New Revision: 83341 Log: #9430: document timedelta str() and repr(). Modified: python/branches/py3k/Doc/library/datetime.rst Modified: python/branches/py3k/Doc/library/datetime.rst ============================================================================== --- python/branches/py3k/Doc/library/datetime.rst (original) +++ python/branches/py3k/Doc/library/datetime.rst Sat Jul 31 13:40:07 2010 @@ -265,6 +265,14 @@ | ``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 @@ (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).
participants (1)
-
georg.brandl