[Python-checkins] cpython: Issue #13727: Add 3 macros to access PyDateTime_Delta members:

amaury.forgeotdarc python-checkins at python.org
Tue Jan 17 21:39:43 CET 2012


http://hg.python.org/cpython/rev/463acb73fd79
changeset:   74470:463acb73fd79
parent:      74466:b039965b0066
user:        Amaury Forgeot d'Arc <amauryfa at gmail.com>
date:        Tue Jan 17 21:31:50 2012 +0100
summary:
  Issue #13727: Add 3 macros to access PyDateTime_Delta members:
PyDateTime_DELTA_GET_DAYS, PyDateTime_DELTA_GET_SECONDS,
PyDateTime_DELTA_GET_MICROSECONDS.

Please use them instead of directly accessing PyDateTime_Delta struct members.

files:
  Doc/c-api/datetime.rst |  25 +++++++++++++++++++++++++
  Include/datetime.h     |   6 ++++++
  Misc/NEWS              |   4 ++++
  3 files changed, 35 insertions(+), 0 deletions(-)


diff --git a/Doc/c-api/datetime.rst b/Doc/c-api/datetime.rst
--- a/Doc/c-api/datetime.rst
+++ b/Doc/c-api/datetime.rst
@@ -170,6 +170,31 @@
    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)
diff --git a/Include/datetime.h b/Include/datetime.h
--- a/Include/datetime.h
+++ b/Include/datetime.h
@@ -135,6 +135,12 @@
      (((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 {
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -2056,6 +2056,10 @@
 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.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list