Skip to content

Commit 8c851fa

Browse files
authored
bpo-29026: Clarify documentation of time.time (GH-34) (GH-418)
(cherry picked from commit 23557d5)
1 parent 80fbacc commit 8c851fa

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

Doc/library/time.rst

+35-7
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,23 @@ semantics of these functions varies among platforms.
1717

1818
An explanation of some terminology and conventions is in order.
1919

20+
.. _epoch:
21+
2022
.. index:: single: epoch
2123

22-
* The :dfn:`epoch` is the point where the time starts. On January 1st of that
23-
year, at 0 hours, the "time since the epoch" is zero. For Unix, the epoch is
24-
1970. To find out what the epoch is, look at ``gmtime(0)``.
24+
* The :dfn:`epoch` is the point where the time starts, and is platform
25+
dependent. For Unix, the epoch is January 1, 1970, 00:00:00 (UTC).
26+
To find out what the epoch is on a given platform, look at
27+
``time.gmtime(0)``.
28+
29+
.. _leap seconds: https://en.wikipedia.org/wiki/Leap_second
30+
31+
.. index:: seconds since the epoch
32+
33+
* The term :dfn:`seconds since the epoch` refers to the total number
34+
of elapsed seconds since the epoch, typically excluding
35+
`leap seconds`_. Leap seconds are excluded from this total on all
36+
POSIX-compliant platforms.
2537

2638
.. index:: single: Year 2038
2739

@@ -463,7 +475,7 @@ The module defines the following functions and data items:
463475

464476
(2)
465477
The range really is ``0`` to ``61``; value ``60`` is valid in
466-
timestamps representing leap seconds and value ``61`` is supported
478+
timestamps representing `leap seconds`_ and value ``61`` is supported
467479
for historical reasons.
468480

469481
(3)
@@ -572,12 +584,28 @@ The module defines the following functions and data items:
572584

573585
.. function:: time()
574586

575-
Return the time in seconds since the epoch as a floating point number.
587+
Return the time in seconds since the epoch_ as a floating point
588+
number. The specific date of the epoch and the handling of
589+
`leap seconds`_ is platform dependent.
590+
On Windows and most Unix systems, the epoch is January 1, 1970,
591+
00:00:00 (UTC) and leap seconds are not counted towards the time
592+
in seconds since the epoch. This is commonly referred to as
593+
`Unix time <https://en.wikipedia.org/wiki/Unix_time>`_.
594+
To find out what the epoch is on a given platform, look at
595+
``gmtime(0)``.
596+
576597
Note that even though the time is always returned as a floating point
577598
number, not all systems provide time with a better precision than 1 second.
578599
While this function normally returns non-decreasing values, it can return a
579-
lower value than a previous call if the system clock has been set back between
580-
the two calls.
600+
lower value than a previous call if the system clock has been set back
601+
between the two calls.
602+
603+
The number returned by :func:`.time` may be converted into a more common
604+
time format (i.e. year, month, day, hour, etc...) in UTC by passing it to
605+
:func:`gmtime` function or in local time by passing it to the
606+
:func:`localtime` function. In both cases a
607+
:class:`struct_time` object is returned, from which the components
608+
of the calendar date may be accessed as attributes.
581609

582610
.. data:: timezone
583611

0 commit comments

Comments
 (0)