Skip to content

Commit 23557d5

Browse files
appeltelvstinner
authored andcommitted
bpo-29026: Clarify documentation of time.time (#34)
* bpo-29026: Clarity documentation of time.time Clarify the documentation of time.time by more precisely defining what is meant by "seconds since the epoch" on most platforms. Additionally explain how gmtime and localtime may be used to extract calendar components and convert to a more common date format. * bpo-29026: Minor improvements for time.time doc * bpo-29026: Consistency fixes for time.time doc
1 parent 1d4601c commit 23557d5

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

Doc/library/time.rst

Lines changed: 35 additions & 7 deletions
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

@@ -467,7 +479,7 @@ The module defines the following functions and data items:
467479

468480
(2)
469481
The range really is ``0`` to ``61``; value ``60`` is valid in
470-
timestamps representing leap seconds and value ``61`` is supported
482+
timestamps representing `leap seconds`_ and value ``61`` is supported
471483
for historical reasons.
472484

473485
(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)