Skip to content

Commit d6cbc74

Browse files
committed
Fix doc
1 parent 30b1d8f commit d6cbc74

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Doc/library/datetime.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ A :class:`timedelta` object represents a duration, the difference between two
261261
>>> (d.days, d.seconds, d.microseconds)
262262
(-1, 86399, 999999)
263263

264+
A :class:`!timedelta` object can be rendered in a human-readable format as follows:
265+
266+
.. code-block:: pycon
267+
268+
>>> def pretty_timedelta(td):
269+
... if td.days >= 0:
270+
... return str(td)
271+
... return f'-({-td!s})'
272+
...
273+
>>> d = timedelta(hour=-1)
274+
>>> d
275+
-1 day, 23:00:00
276+
>>> pretty_timedelta(d)
277+
-(1:00:00)
278+
264279
265280
Class attributes:
266281

0 commit comments

Comments
 (0)