diff options
author | Cheryl Sabella <cheryl.sabella@gmail.com> | 2017-10-11 13:29:14 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2017-10-11 13:29:14 (GMT) |
commit | 703ff381ffa946c23e7e25b0ae93a636a2607a40 (patch) | |
tree | 537b02be8672722f1f2b9606bf925e94e959305a /Doc/library/time.rst | |
parent | eeb5ffd54e56dd89a99c74eb512c36d62649cfec (diff) | |
download | cpython-703ff381ffa946c23e7e25b0ae93a636a2607a40.zip cpython-703ff381ffa946c23e7e25b0ae93a636a2607a40.tar.gz cpython-703ff381ffa946c23e7e25b0ae93a636a2607a40.tar.bz2 |
bpo-28157: Improvements for the time module documentation (GH-928)
* Separated functions and constants descriptions in sections.
* Added a note about the limitations of timezone constants.
* Removed redundant lists from the module docstring.
Diffstat (limited to 'Doc/library/time.rst')
-rw-r--r-- | Doc/library/time.rst | 202 |
1 files changed, 115 insertions, 87 deletions
diff --git a/Doc/library/time.rst b/Doc/library/time.rst index 179762e..25a4ab5 100644 --- a/Doc/library/time.rst +++ b/Doc/library/time.rst @@ -118,14 +118,10 @@ An explanation of some terminology and conventions is in order. +-------------------------+-------------------------+-------------------------+ -The module defines the following functions and data items: - -.. data:: altzone - - The offset of the local DST timezone, in seconds west of UTC, if one is defined. - This is negative if the local DST timezone is east of UTC (as in Western Europe, - including the UK). Only use this if ``daylight`` is nonzero. +.. _time-functions: +Functions +--------- .. function:: asctime([t]) @@ -181,7 +177,8 @@ The module defines the following functions and data items: .. function:: clock_getres(clk_id) - Return the resolution (precision) of the specified clock *clk_id*. + Return the resolution (precision) of the specified clock *clk_id*. Refer to + :ref:`time-clock-id-constants` for a list of accepted values for *clk_id*. Availability: Unix. @@ -190,7 +187,8 @@ The module defines the following functions and data items: .. function:: clock_gettime(clk_id) - Return the time of the specified clock *clk_id*. + Return the time of the specified clock *clk_id*. Refer to + :ref:`time-clock-id-constants` for a list of accepted values for *clk_id*. Availability: Unix. @@ -199,66 +197,8 @@ The module defines the following functions and data items: .. function:: clock_settime(clk_id, time) - Set the time of the specified clock *clk_id*. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. data:: CLOCK_HIGHRES - - The Solaris OS has a CLOCK_HIGHRES timer that attempts to use an optimal - hardware source, and may give close to nanosecond resolution. CLOCK_HIGHRES - is the nonadjustable, high-resolution clock. - - Availability: Solaris. - - .. versionadded:: 3.3 - - -.. data:: CLOCK_MONOTONIC - - Clock that cannot be set and represents monotonic time since some unspecified - starting point. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. data:: CLOCK_MONOTONIC_RAW - - Similar to :data:`CLOCK_MONOTONIC`, but provides access to a raw - hardware-based time that is not subject to NTP adjustments. - - Availability: Linux 2.6.28 or later. - - .. versionadded:: 3.3 - - -.. data:: CLOCK_PROCESS_CPUTIME_ID - - High-resolution per-process timer from the CPU. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. data:: CLOCK_REALTIME - - System-wide real-time clock. Setting this clock requires appropriate - privileges. - - Availability: Unix. - - .. versionadded:: 3.3 - - -.. data:: CLOCK_THREAD_CPUTIME_ID - - Thread-specific CPU-time clock. + Set the time of the specified clock *clk_id*. Currently, + :data:`CLOCK_REALTIME` is the only accepted value for *clk_id*. Availability: Unix. @@ -273,11 +213,6 @@ The module defines the following functions and data items: ``asctime(localtime(secs))``. Locale information is not used by :func:`ctime`. -.. data:: daylight - - Nonzero if a DST timezone is defined. - - .. function:: get_clock_info(name) Get information on the specified clock as a namespace object. @@ -295,7 +230,7 @@ The module defines the following functions and data items: - *adjustable*: ``True`` if the clock can be changed automatically (e.g. by a NTP daemon) or manually by the system administrator, ``False`` otherwise - *implementation*: The name of the underlying C function used to get - the clock value + the clock value. Refer to :ref:`time-clock-id-constants` for possible values. - *monotonic*: ``True`` if the clock cannot go backward, ``False`` otherwise - *resolution*: The resolution of the clock in seconds (:class:`float`) @@ -623,18 +558,6 @@ The module defines the following functions and data items: :class:`struct_time` object is returned, from which the components of the calendar date may be accessed as attributes. -.. data:: timezone - - The offset of the local (non-DST) timezone, in seconds west of UTC (negative in - most of Western Europe, positive in the US, zero in the UK). - - -.. data:: tzname - - A tuple of two strings: the first is the name of the local non-DST timezone, the - second is the name of the local DST timezone. If no DST timezone is defined, - the second string should not be used. - .. function:: tzset() @@ -724,6 +647,111 @@ The module defines the following functions and data items: ('EET', 'EEST') +.. _time-clock-id-constants: + +Clock ID Constants +------------------ + +These constants are used as parameters for :func:`clock_getres` and +:func:`clock_gettime`. + +.. data:: CLOCK_HIGHRES + + The Solaris OS has a ``CLOCK_HIGHRES`` timer that attempts to use an optimal + hardware source, and may give close to nanosecond resolution. + ``CLOCK_HIGHRES`` is the nonadjustable, high-resolution clock. + + Availability: Solaris. + + .. versionadded:: 3.3 + + +.. data:: CLOCK_MONOTONIC + + Clock that cannot be set and represents monotonic time since some unspecified + starting point. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. data:: CLOCK_MONOTONIC_RAW + + Similar to :data:`CLOCK_MONOTONIC`, but provides access to a raw + hardware-based time that is not subject to NTP adjustments. + + Availability: Linux 2.6.28 or later. + + .. versionadded:: 3.3 + + +.. data:: CLOCK_PROCESS_CPUTIME_ID + + High-resolution per-process timer from the CPU. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. data:: CLOCK_THREAD_CPUTIME_ID + + Thread-specific CPU-time clock. + + Availability: Unix. + + .. versionadded:: 3.3 + + +The following constant is the only parameter that can be sent to +:func:`clock_settime`. + +.. data:: CLOCK_REALTIME + + System-wide real-time clock. Setting this clock requires appropriate + privileges. + + Availability: Unix. + + .. versionadded:: 3.3 + + +.. _time-timezone-constants: + +Timezone Constants +------------------- + +.. data:: altzone + + The offset of the local DST timezone, in seconds west of UTC, if one is defined. + This is negative if the local DST timezone is east of UTC (as in Western Europe, + including the UK). Only use this if ``daylight`` is nonzero. See note below. + +.. data:: daylight + + Nonzero if a DST timezone is defined. See note below. + +.. data:: timezone + + The offset of the local (non-DST) timezone, in seconds west of UTC (negative in + most of Western Europe, positive in the US, zero in the UK). See note below. + +.. data:: tzname + + A tuple of two strings: the first is the name of the local non-DST timezone, the + second is the name of the local DST timezone. If no DST timezone is defined, + the second string should not be used. See note below. + +.. note:: + + For the above Timezone constants (:data:`altzone`, :data:`daylight`, :data:`timezone`, + and :data:`tzname`), the value is determined by the timezone rules in effect + at module load time or the last time :func:`tzset` is called and may be incorrect + for times in the past. It is recommended to use the :attr:`tm_gmtoff` and + :attr:`tm_zone` results from :func:`localtime` to obtain timezone information. + + .. seealso:: Module :mod:`datetime` |