Skip to content

Commit c83fc9c

Browse files
authored
bpo-31327: Update time documentation to reflect possible errors (GH-31460)
As per the comments, this mirrors the [datetime documentation](https://docs.python.org/3/library/datetime.html#datetime.datetime.fromtimestamp). ``` >>> import time >>> time.localtime(999999999999999999999) Traceback (most recent call last): File "<stdin>", line 1, in <module> OverflowError: timestamp out of range for platform time_t >>> time.localtime(-3600) Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: [Errno 22] Invalid argument ```
1 parent 6f3b9e2 commit c83fc9c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Doc/library/time.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ Functions
257257
:const:`None`, the current time as returned by :func:`.time` is used. The dst
258258
flag is set to ``1`` when DST applies to the given time.
259259

260+
:func:`localtime` may raise :exc:`OverflowError`, if the timestamp is
261+
outside the range of values supported by the platform C :c:func:`localtime`
262+
or :c:func:`gmtime` functions, and :exc:`OSError` on :c:func:`localtime` or
263+
:c:func:`gmtime` failure. It's common for this to be restricted to years
264+
between 1970 and 2038.
265+
260266

261267
.. function:: mktime(t)
262268

0 commit comments

Comments
 (0)