bpo-29026: Clarify documentation of time.time (#34) · python/cpython@23557d5

@@ -17,11 +17,23 @@ semantics of these functions varies among platforms.

17171818

An explanation of some terminology and conventions is in order.

191920+

.. _epoch:

21+2022

.. index:: single: epoch

212322-

* 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.

25372638

.. index:: single: Year 2038

2739

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

467479468480

(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.

472484473485

(3)

@@ -572,12 +584,28 @@ The module defines the following functions and data items:

572584573585

.. function:: time()

574586575-

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.

581609582610

.. data:: timezone

583611