@@ -124,39 +124,32 @@ typedef struct
124
124
// o is a pointer to a time or a datetime object.
125
125
#define _PyDateTime_HAS_TZINFO (o ) (((_PyDateTime_BaseTZInfo *)(o))->hastzinfo)
126
126
127
- #define PyDateTime_GET_YEAR (o ) ((((PyDateTime_Date*)o)->data[0] << 8) | \
128
- ((PyDateTime_Date*)o)->data[1])
129
- #define PyDateTime_GET_MONTH (o ) (((PyDateTime_Date*)o)->data[2])
130
- #define PyDateTime_GET_DAY (o ) (((PyDateTime_Date*)o)->data[3])
131
-
132
- #define PyDateTime_DATE_GET_HOUR (o ) (((PyDateTime_DateTime*)o)->data[4])
133
- #define PyDateTime_DATE_GET_MINUTE (o ) (((PyDateTime_DateTime*)o)->data[5])
134
- #define PyDateTime_DATE_GET_SECOND (o ) (((PyDateTime_DateTime*)o)->data[6])
135
- #define PyDateTime_DATE_GET_MICROSECOND (o ) \
136
- ((((PyDateTime_DateTime*)o)->data[7] << 16) | \
137
- (((PyDateTime_DateTime*)o)->data[8] << 8) | \
138
- ((PyDateTime_DateTime*)o)->data[9])
139
- #define PyDateTime_DATE_GET_FOLD (o ) (((PyDateTime_DateTime*)o)->fold)
140
- #define PyDateTime_DATE_GET_TZINFO (o ) (_PyDateTime_HAS_TZINFO(o) ? \
141
- ((PyDateTime_DateTime *)(o))->tzinfo : Py_None)
127
+ #define PyDateTime_GET_YEAR (o ) ((int)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "year")))
128
+ #define PyDateTime_GET_MONTH (o ) ((unsigned char)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "month")))
129
+ #define PyDateTime_GET_DAY (o ) ((unsigned char)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "day")))
130
+
131
+ #define PyDateTime_DATE_GET_HOUR (o ) ((unsigned char)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "hour")))
132
+ #define PyDateTime_DATE_GET_MINUTE (o ) ((unsigned char)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "minute")))
133
+ #define PyDateTime_DATE_GET_SECOND (o ) ((unsigned char)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "second")))
134
+ #define PyDateTime_DATE_GET_MICROSECOND (o ) ((int)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "microsecond")))
135
+ #define PyDateTime_DATE_GET_FOLD (o ) ((unsigned char)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "fold")))
136
+ // TODO borrow
137
+ #define PyDateTime_DATE_GET_TZINFO (o ) (PyObject_GetAttrString((PyObject*)o, "tzinfo"))
142
138
143
139
/* Apply for time instances. */
144
- #define PyDateTime_TIME_GET_HOUR (o ) (((PyDateTime_Time*)o)->data[0])
145
- #define PyDateTime_TIME_GET_MINUTE (o ) (((PyDateTime_Time*)o)->data[1])
146
- #define PyDateTime_TIME_GET_SECOND (o ) (((PyDateTime_Time*)o)->data[2])
147
- #define PyDateTime_TIME_GET_MICROSECOND (o ) \
148
- ((((PyDateTime_Time*)o)->data[3] << 16) | \
149
- (((PyDateTime_Time*)o)->data[4] << 8) | \
150
- ((PyDateTime_Time*)o)->data[5])
151
- #define PyDateTime_TIME_GET_FOLD (o ) (((PyDateTime_Time*)o)->fold)
152
- #define PyDateTime_TIME_GET_TZINFO (o ) (_PyDateTime_HAS_TZINFO(o) ? \
153
- ((PyDateTime_Time *)(o))->tzinfo : Py_None)
140
+ #define PyDateTime_TIME_GET_HOUR (o ) ((unsigned char)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "hour")))
141
+ #define PyDateTime_TIME_GET_MINUTE (o ) ((unsigned char)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "minute")))
142
+ #define PyDateTime_TIME_GET_SECOND (o ) ((unsigned char)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "second")))
143
+ #define PyDateTime_TIME_GET_MICROSECOND (o ) ((int)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "microsecond")))
144
+ #define PyDateTime_TIME_GET_FOLD (o ) ((unsigned char)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "fold")))
145
+ // TODO borrow
146
+ #define PyDateTime_TIME_GET_TZINFO (o ) (PyObject_GetAttrString((PyObject*)o, "tzinfo"))
154
147
155
148
/* Apply for time delta instances */
156
- #define PyDateTime_DELTA_GET_DAYS (o ) (((PyDateTime_Delta *)o)-> days)
157
- #define PyDateTime_DELTA_GET_SECONDS (o ) (((PyDateTime_Delta *)o)-> seconds)
158
- #define PyDateTime_DELTA_GET_MICROSECONDS (o ) \
159
- (((PyDateTime_Delta*)o)->microseconds)
149
+ #define PyDateTime_DELTA_GET_DAYS (o ) ((int)PyLong_AsLong(PyObject_GetAttrString((PyObject *)o, " days")) )
150
+ #define PyDateTime_DELTA_GET_SECONDS (o ) ((int)PyLong_AsLong(PyObject_GetAttrString((PyObject *)o, " seconds")) )
151
+ #define PyDateTime_DELTA_GET_MICROSECONDS (o ) ((int)PyLong_AsLong(PyObject_GetAttrString((PyObject*)o, "microseconds")))
152
+
160
153
161
154
162
155
/* Define structure for C API. */
0 commit comments