gh-107298: Fix C API datetime documentation (GH-108034)

This commit is contained in:
Serhiy Storchaka 2023-08-21 21:15:46 +03:00 committed by GitHub
parent 18fc543b37
commit d63972e289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 15 deletions

View File

@ -8,11 +8,54 @@ DateTime Objects
Various date and time objects are supplied by the :mod:`datetime` module. Various date and time objects are supplied by the :mod:`datetime` module.
Before using any of these functions, the header file :file:`datetime.h` must be Before using any of these functions, the header file :file:`datetime.h` must be
included in your source (note that this is not included by :file:`Python.h`), included in your source (note that this is not included by :file:`Python.h`),
and the macro :c:macro:`PyDateTime_IMPORT` must be invoked, usually as part of and the macro :c:macro:`!PyDateTime_IMPORT` must be invoked, usually as part of
the module initialisation function. The macro puts a pointer to a C structure the module initialisation function. The macro puts a pointer to a C structure
into a static variable, :c:data:`PyDateTimeAPI`, that is used by the following into a static variable, :c:data:`!PyDateTimeAPI`, that is used by the following
macros. macros.
.. c:type:: PyDateTime_Date
This subtype of :c:type:`PyObject` represents a Python date object.
.. c:type:: PyDateTime_DateTime
This subtype of :c:type:`PyObject` represents a Python datetime object.
.. c:type:: PyDateTime_Time
This subtype of :c:type:`PyObject` represents a Python time object.
.. c:type:: PyDateTime_Delta
This subtype of :c:type:`PyObject` represents the difference between two datetime values.
.. c:var:: PyTypeObject PyDateTime_DateType
This instance of :c:type:`PyTypeObject` represents the Python date type;
it is the same object as :class:`datetime.date` in the Python layer.
.. c:var:: PyTypeObject PyDateTime_DateTimeType
This instance of :c:type:`PyTypeObject` represents the Python datetime type;
it is the same object as :class:`datetime.datetime` in the Python layer.
.. c:var:: PyTypeObject PyDateTime_TimeType
This instance of :c:type:`PyTypeObject` represents the Python time type;
it is the same object as :class:`datetime.time` in the Python layer.
.. c:var:: PyTypeObject PyDateTime_DeltaType
This instance of :c:type:`PyTypeObject` represents Python type for
the difference between two datetime values;
it is the same object as :class:`datetime.timedelta` in the Python layer.
.. c:var:: PyTypeObject PyDateTime_TZInfoType
This instance of :c:type:`PyTypeObject` represents the Python time zone info type;
it is the same object as :class:`datetime.tzinfo` in the Python layer.
Macro for access to the UTC singleton: Macro for access to the UTC singleton:
.. c:var:: PyObject* PyDateTime_TimeZone_UTC .. c:var:: PyObject* PyDateTime_TimeZone_UTC
@ -28,7 +71,7 @@ Type-check macros:
.. c:function:: int PyDate_Check(PyObject *ob) .. c:function:: int PyDate_Check(PyObject *ob)
Return true if *ob* is of type :c:data:`PyDateTime_DateType` or a subtype of Return true if *ob* is of type :c:data:`PyDateTime_DateType` or a subtype of
:c:data:`PyDateTime_DateType`. *ob* must not be ``NULL``. This function always :c:data:`!PyDateTime_DateType`. *ob* must not be ``NULL``. This function always
succeeds. succeeds.
@ -41,7 +84,7 @@ Type-check macros:
.. c:function:: int PyDateTime_Check(PyObject *ob) .. c:function:: int PyDateTime_Check(PyObject *ob)
Return true if *ob* is of type :c:data:`PyDateTime_DateTimeType` or a subtype of Return true if *ob* is of type :c:data:`PyDateTime_DateTimeType` or a subtype of
:c:data:`PyDateTime_DateTimeType`. *ob* must not be ``NULL``. This function always :c:data:`!PyDateTime_DateTimeType`. *ob* must not be ``NULL``. This function always
succeeds. succeeds.
@ -54,7 +97,7 @@ Type-check macros:
.. c:function:: int PyTime_Check(PyObject *ob) .. c:function:: int PyTime_Check(PyObject *ob)
Return true if *ob* is of type :c:data:`PyDateTime_TimeType` or a subtype of Return true if *ob* is of type :c:data:`PyDateTime_TimeType` or a subtype of
:c:data:`PyDateTime_TimeType`. *ob* must not be ``NULL``. This function always :c:data:`!PyDateTime_TimeType`. *ob* must not be ``NULL``. This function always
succeeds. succeeds.
@ -67,7 +110,7 @@ Type-check macros:
.. c:function:: int PyDelta_Check(PyObject *ob) .. c:function:: int PyDelta_Check(PyObject *ob)
Return true if *ob* is of type :c:data:`PyDateTime_DeltaType` or a subtype of Return true if *ob* is of type :c:data:`PyDateTime_DeltaType` or a subtype of
:c:data:`PyDateTime_DeltaType`. *ob* must not be ``NULL``. This function always :c:data:`!PyDateTime_DeltaType`. *ob* must not be ``NULL``. This function always
succeeds. succeeds.
@ -80,7 +123,7 @@ Type-check macros:
.. c:function:: int PyTZInfo_Check(PyObject *ob) .. c:function:: int PyTZInfo_Check(PyObject *ob)
Return true if *ob* is of type :c:data:`PyDateTime_TZInfoType` or a subtype of Return true if *ob* is of type :c:data:`PyDateTime_TZInfoType` or a subtype of
:c:data:`PyDateTime_TZInfoType`. *ob* must not be ``NULL``. This function always :c:data:`!PyDateTime_TZInfoType`. *ob* must not be ``NULL``. This function always
succeeds. succeeds.
@ -133,7 +176,7 @@ Macros to create objects:
:class:`datetime.timedelta` objects. :class:`datetime.timedelta` objects.
.. c:function:: PyObject* PyTimeZone_FromOffset(PyDateTime_DeltaType* offset) .. c:function:: PyObject* PyTimeZone_FromOffset(PyObject *offset)
Return a :class:`datetime.timezone` object with an unnamed fixed offset Return a :class:`datetime.timezone` object with an unnamed fixed offset
represented by the *offset* argument. represented by the *offset* argument.
@ -141,7 +184,7 @@ Macros to create objects:
.. versionadded:: 3.7 .. versionadded:: 3.7
.. c:function:: PyObject* PyTimeZone_FromOffsetAndName(PyDateTime_DeltaType* offset, PyUnicode* name) .. c:function:: PyObject* PyTimeZone_FromOffsetAndName(PyObject *offset, PyObject *name)
Return a :class:`datetime.timezone` object with a fixed offset represented Return a :class:`datetime.timezone` object with a fixed offset represented
by the *offset* argument and with tzname *name*. by the *offset* argument and with tzname *name*.
@ -150,8 +193,8 @@ Macros to create objects:
Macros to extract fields from date objects. The argument must be an instance of Macros to extract fields from date objects. The argument must be an instance of
:c:data:`PyDateTime_Date`, including subclasses (such as :c:type:`PyDateTime_Date`, including subclasses (such as
:c:data:`PyDateTime_DateTime`). The argument must not be ``NULL``, and the type is :c:type:`PyDateTime_DateTime`). The argument must not be ``NULL``, and the type is
not checked: not checked:
.. c:function:: int PyDateTime_GET_YEAR(PyDateTime_Date *o) .. c:function:: int PyDateTime_GET_YEAR(PyDateTime_Date *o)
@ -170,7 +213,7 @@ not checked:
Macros to extract fields from datetime objects. The argument must be an Macros to extract fields from datetime objects. The argument must be an
instance of :c:data:`PyDateTime_DateTime`, including subclasses. The argument instance of :c:type:`PyDateTime_DateTime`, including subclasses. The argument
must not be ``NULL``, and the type is not checked: must not be ``NULL``, and the type is not checked:
.. c:function:: int PyDateTime_DATE_GET_HOUR(PyDateTime_DateTime *o) .. c:function:: int PyDateTime_DATE_GET_HOUR(PyDateTime_DateTime *o)
@ -208,7 +251,7 @@ must not be ``NULL``, and the type is not checked:
Macros to extract fields from time objects. The argument must be an instance of Macros to extract fields from time objects. The argument must be an instance of
:c:data:`PyDateTime_Time`, including subclasses. The argument must not be ``NULL``, :c:type:`PyDateTime_Time`, including subclasses. The argument must not be ``NULL``,
and the type is not checked: and the type is not checked:
.. c:function:: int PyDateTime_TIME_GET_HOUR(PyDateTime_Time *o) .. c:function:: int PyDateTime_TIME_GET_HOUR(PyDateTime_Time *o)
@ -246,7 +289,7 @@ and the type is not checked:
Macros to extract fields from time delta objects. The argument must be an Macros to extract fields from time delta objects. The argument must be an
instance of :c:data:`PyDateTime_Delta`, including subclasses. The argument must instance of :c:type:`PyDateTime_Delta`, including subclasses. The argument must
not be ``NULL``, and the type is not checked: not be ``NULL``, and the type is not checked:
.. c:function:: int PyDateTime_DELTA_GET_DAYS(PyDateTime_Delta *o) .. c:function:: int PyDateTime_DELTA_GET_DAYS(PyDateTime_Delta *o)

View File

@ -2,7 +2,6 @@
# as tested on the CI via check-warnings.py in reusable-docs.yml. # as tested on the CI via check-warnings.py in reusable-docs.yml.
# Keep lines sorted lexicographically to help avoid merge conflicts. # Keep lines sorted lexicographically to help avoid merge conflicts.
Doc/c-api/datetime.rst
Doc/c-api/descriptor.rst Doc/c-api/descriptor.rst
Doc/c-api/exceptions.rst Doc/c-api/exceptions.rst
Doc/c-api/file.rst Doc/c-api/file.rst