aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Doc/library/datetime.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/datetime.rst')
-rw-r--r--Doc/library/datetime.rst30
1 files changed, 25 insertions, 5 deletions
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 1ce2013f05d..16ed3215bc2 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -261,6 +261,22 @@ A :class:`timedelta` object represents a duration, the difference between two
>>> (d.days, d.seconds, d.microseconds)
(-1, 86399, 999999)
+ Since the string representation of :class:`!timedelta` objects can be confusing,
+ use the following recipe to produce a more readable format:
+
+ .. code-block:: pycon
+
+ >>> def pretty_timedelta(td):
+ ... if td.days >= 0:
+ ... return str(td)
+ ... return f'-({-td!s})'
+ ...
+ >>> d = timedelta(hours=-1)
+ >>> str(d) # not human-friendly
+ '-1 day, 23:00:00'
+ >>> pretty_timedelta(d)
+ '-(1:00:00)'
+
Class attributes:
@@ -1486,11 +1502,11 @@ Instance methods:
returned by :func:`time.time`.
Naive :class:`.datetime` instances are assumed to represent local
- time and this method relies on the platform C :c:func:`mktime`
- function to perform the conversion. Since :class:`.datetime`
- supports wider range of values than :c:func:`mktime` on many
- platforms, this method may raise :exc:`OverflowError` or :exc:`OSError`
- for times far in the past or far in the future.
+ time and this method relies on platform C functions to perform
+ the conversion. Since :class:`.datetime` supports a wider range of
+ values than the platform C functions on many platforms, this
+ method may raise :exc:`OverflowError` or :exc:`OSError` for times
+ far in the past or far in the future.
For aware :class:`.datetime` instances, the return value is computed
as::
@@ -1503,6 +1519,10 @@ Instance methods:
The :meth:`timestamp` method uses the :attr:`.fold` attribute to
disambiguate the times during a repeated interval.
+ .. versionchanged:: 3.6
+ This method no longer relies on the platform C :c:func:`mktime`
+ function to perform conversions.
+
.. note::
There is no method to obtain the POSIX timestamp directly from a