]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #13727: Add 3 macros to access PyDateTime_Delta members:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Tue, 17 Jan 2012 20:31:50 +0000 (21:31 +0100)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Tue, 17 Jan 2012 20:31:50 +0000 (21:31 +0100)
PyDateTime_DELTA_GET_DAYS, PyDateTime_DELTA_GET_SECONDS,
PyDateTime_DELTA_GET_MICROSECONDS.

Please use them instead of directly accessing PyDateTime_Delta struct members.

Doc/c-api/datetime.rst
Include/datetime.h
Misc/NEWS

index fcd13954a335a6025dfb470690c8b76e1af8a3d0..39542bd17a3b4a77364dcb6c1684872d5bfd24be 100644 (file)
@@ -170,6 +170,31 @@ and the type is not checked:
    Return the microsecond, as an int from 0 through 999999.
 
 
+Macros to extract fields from time delta objects.  The argument must be an
+instance of :c:data:`PyDateTime_Delta`, including subclasses. The argument must
+not be *NULL*, and the type is not checked:
+
+.. c:function:: int PyDateTime_DELTA_GET_DAYS(PyDateTime_Delta *o)
+
+   Return the number of days, as an int from -999999999 to 999999999.
+
+   .. versionadded:: 3.3
+
+
+.. c:function:: int PyDateTime_DELTA_GET_SECONDS(PyDateTime_Delta *o)
+
+   Return the number of seconds, as an int from 0 through 86399.
+
+   .. versionadded:: 3.3
+
+
+.. c:function:: int PyDateTime_DELTA_GET_MICROSECOND(PyDateTime_Delta *o)
+
+   Return the number of microseconds, as an int from 0 through 999999.
+
+   .. versionadded:: 3.3
+
+
 Macros for the convenience of modules implementing the DB API:
 
 .. c:function:: PyObject* PyDateTime_FromTimestamp(PyObject *args)
index db57a18e66b34803f360e3956b9de9f4bc737e64..41e3bcf865c9e448fde8be531a99c7f39fabccb3 100644 (file)
@@ -135,6 +135,12 @@ typedef struct
      (((PyDateTime_Time*)o)->data[4] << 8)  |           \
       ((PyDateTime_Time*)o)->data[5])
 
+/* Apply for time delta instances */
+#define PyDateTime_DELTA_GET_DAYS(o)         (((PyDateTime_Delta*)o)->days)
+#define PyDateTime_DELTA_GET_SECONDS(o)      (((PyDateTime_Delta*)o)->seconds)
+#define PyDateTime_DELTA_GET_MICROSECONDS(o)            \
+    (((PyDateTime_Delta*)o)->microseconds)
+
 
 /* Define structure for C API. */
 typedef struct {
index a2954d8b4e1ef4da9bb8c20ce26276e16b0ab5c6..8178a92b89d5e91c9c2db6e6b5f559e8653734e0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -2056,6 +2056,10 @@ Tests
 C-API
 -----
 
+- Issue #13727: Add 3 macros to access PyDateTime_Delta members:
+  PyDateTime_DELTA_GET_DAYS, PyDateTime_DELTA_GET_SECONDS,
+  PyDateTime_DELTA_GET_MICROSECONDS.
+
 - Issue #10542: Add 4 macros to work with surrogates: Py_UNICODE_IS_SURROGATE,
   Py_UNICODE_IS_HIGH_SURROGATE, Py_UNICODE_IS_LOW_SURROGATE,
   Py_UNICODE_JOIN_SURROGATES.