]> granicus.if.org Git - python/commitdiff
Closes issue #22791: Improved datetime from timestamp methods documentation.
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Sun, 1 Mar 2015 19:52:07 +0000 (14:52 -0500)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Sun, 1 Mar 2015 19:52:07 +0000 (14:52 -0500)
Original patch by Akira Li.

Doc/library/datetime.rst
Lib/datetime.py
Modules/_datetimemodule.c

index 7a9f93cd238fe85531b251351efa8fb67666bf4c..f82f425ac40a6ff4369d0ea51c34022435c4ea0c 100644 (file)
@@ -759,13 +759,19 @@ Other constructors, all class methods:
    :attr:`tzinfo` ``None``. This may raise :exc:`OverflowError`, if the timestamp is
    out of the range of values supported by the platform C :c:func:`gmtime` function,
    and :exc:`OSError` on :c:func:`gmtime` failure.
-   It's common for this to be restricted to years in 1970 through 2038. See also
-   :meth:`fromtimestamp`.
+   It's common for this to be restricted to years in 1970 through 2038.
+
+   To get an aware :class:`.datetime` object, call :meth:`fromtimestamp`::
+
+     datetime.fromtimestamp(timestamp, timezone.utc)
+
+   On the POSIX compliant platforms, it is equivalent to the following
+   expression::
 
-   On the POSIX compliant platforms, ``utcfromtimestamp(timestamp)``
-   is equivalent to the following expression::
+     datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=timestamp)
 
-     datetime(1970, 1, 1) + timedelta(seconds=timestamp)
+   except the latter formula always supports the full years range: between
+   :const:`MINYEAR` and :const:`MAXYEAR` inclusive.
 
    .. versionchanged:: 3.3
       Raise :exc:`OverflowError` instead of :exc:`ValueError` if the timestamp
index 2768e9bffd2edc5be7168f88ce307c8ed98333bd..de574724b865de9e02b328fe16167ab2e3c74a23 100644 (file)
@@ -1393,7 +1393,7 @@ class datetime(date):
 
     @classmethod
     def utcfromtimestamp(cls, t):
-        "Construct a UTC datetime from a POSIX timestamp (like time.time())."
+        """Construct a naive UTC datetime from a POSIX timestamp."""
         t, frac = divmod(t, 1.0)
         us = int(frac * 1e6)
 
index 701c58773b57b82db60d90dfa50e4edd5c946c22..09285d919dea5502bbe38ca1c47386f5a126e5cd 100644 (file)
@@ -5020,8 +5020,7 @@ static PyMethodDef datetime_methods[] = {
 
     {"utcfromtimestamp", (PyCFunction)datetime_utcfromtimestamp,
      METH_VARARGS | METH_CLASS,
-     PyDoc_STR("timestamp -> UTC datetime from a POSIX timestamp "
-               "(like time.time()).")},
+     PyDoc_STR("Construct a naive UTC datetime from a POSIX timestamp.")},
 
     {"strptime", (PyCFunction)datetime_strptime,
      METH_VARARGS | METH_CLASS,