| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef DATETIME_H |
| 5 |
#define DATETIME_H |
| 6 |
#ifdef __cplusplus |
| 7 |
extern "C" { |
| 8 |
#endif |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#define _PyDateTime_DATE_DATASIZE 4 |
| 26 |
|
| 27 |
|
| 28 |
#define _PyDateTime_TIME_DATASIZE 6 |
| 29 |
|
| 30 |
|
| 31 |
#define _PyDateTime_DATETIME_DATASIZE 10 |
| 32 |
|
| 33 |
|
| 34 |
typedef struct |
| 35 |
{ |
| 36 |
PyObject_HEAD |
| 37 |
long hashcode; |
| 38 |
int days; |
| 39 |
int seconds; |
| 40 |
int microseconds; |
| 41 |
} PyDateTime_Delta; |
| 42 |
|
| 43 |
typedef struct |
| 44 |
{ |
| 45 |
PyObject_HEAD |
| 46 |
} PyDateTime_TZInfo; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
#define _PyTZINFO_HEAD \ |
| 53 |
PyObject_HEAD \ |
| 54 |
long hashcode; \ |
| 55 |
char hastzinfo; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
typedef struct |
| 62 |
{ |
| 63 |
_PyTZINFO_HEAD |
| 64 |
} _PyDateTime_BaseTZInfo; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
#define _PyDateTime_TIMEHEAD \ |
| 73 |
_PyTZINFO_HEAD \ |
| 74 |
unsigned char data[_PyDateTime_TIME_DATASIZE]; |
| 75 |
|
| 76 |
typedef struct |
| 77 |
{ |
| 78 |
_PyDateTime_TIMEHEAD |
| 79 |
} _PyDateTime_BaseTime; |
| 80 |
|
| 81 |
typedef struct |
| 82 |
{ |
| 83 |
_PyDateTime_TIMEHEAD |
| 84 |
PyObject *tzinfo; |
| 85 |
} PyDateTime_Time; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
typedef struct |
| 94 |
{ |
| 95 |
_PyTZINFO_HEAD |
| 96 |
unsigned char data[_PyDateTime_DATE_DATASIZE]; |
| 97 |
} PyDateTime_Date; |
| 98 |
|
| 99 |
#define _PyDateTime_DATETIMEHEAD \ |
| 100 |
_PyTZINFO_HEAD \ |
| 101 |
unsigned char data[_PyDateTime_DATETIME_DATASIZE]; |
| 102 |
|
| 103 |
typedef struct |
| 104 |
{ |
| 105 |
_PyDateTime_DATETIMEHEAD |
| 106 |
} _PyDateTime_BaseDateTime; |
| 107 |
|
| 108 |
typedef struct |
| 109 |
{ |
| 110 |
_PyDateTime_DATETIMEHEAD |
| 111 |
PyObject *tzinfo; |
| 112 |
} PyDateTime_DateTime; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
#define PyDateTime_GET_YEAR(o) ((((PyDateTime_Date*)o)->data[0] << 8) | \ |
| 117 |
((PyDateTime_Date*)o)->data[1]) |
| 118 |
#define PyDateTime_GET_MONTH(o) (((PyDateTime_Date*)o)->data[2]) |
| 119 |
#define PyDateTime_GET_DAY(o) (((PyDateTime_Date*)o)->data[3]) |
| 120 |
|
| 121 |
#define PyDateTime_DATE_GET_HOUR(o) (((PyDateTime_DateTime*)o)->data[4]) |
| 122 |
#define PyDateTime_DATE_GET_MINUTE(o) (((PyDateTime_DateTime*)o)->data[5]) |
| 123 |
#define PyDateTime_DATE_GET_SECOND(o) (((PyDateTime_DateTime*)o)->data[6]) |
| 124 |
#define PyDateTime_DATE_GET_MICROSECOND(o) \ |
| 125 |
((((PyDateTime_DateTime*)o)->data[7] << 16) | \ |
| 126 |
(((PyDateTime_DateTime*)o)->data[8] << 8) | \ |
| 127 |
((PyDateTime_DateTime*)o)->data[9]) |
| 128 |
|
| 129 |
|
| 130 |
#define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)o)->data[0]) |
| 131 |
#define PyDateTime_TIME_GET_MINUTE(o) (((PyDateTime_Time*)o)->data[1]) |
| 132 |
#define PyDateTime_TIME_GET_SECOND(o) (((PyDateTime_Time*)o)->data[2]) |
| 133 |
#define PyDateTime_TIME_GET_MICROSECOND(o) \ |
| 134 |
((((PyDateTime_Time*)o)->data[3] << 16) | \ |
| 135 |
(((PyDateTime_Time*)o)->data[4] << 8) | \ |
| 136 |
((PyDateTime_Time*)o)->data[5]) |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
typedef struct { |
| 141 |
|
| 142 |
PyTypeObject *DateType; |
| 143 |
PyTypeObject *DateTimeType; |
| 144 |
PyTypeObject *TimeType; |
| 145 |
PyTypeObject *DeltaType; |
| 146 |
PyTypeObject *TZInfoType; |
| 147 |
|
| 148 |
|
| 149 |
PyObject *(*Date_FromDate)(int, int, int, PyTypeObject*); |
| 150 |
PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int, |
| 151 |
PyObject*, PyTypeObject*); |
| 152 |
PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*); |
| 153 |
PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*); |
| 154 |
|
| 155 |
|
| 156 |
PyObject *(*DateTime_FromTimestamp)(PyObject*, PyObject*, PyObject*); |
| 157 |
PyObject *(*Date_FromTimestamp)(PyObject*, PyObject*); |
| 158 |
|
| 159 |
} PyDateTime_CAPI; |
| 160 |
|
| 161 |
#define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI" |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
#define DATETIME_API_MAGIC 0x414548d5 |
| 166 |
|
| 167 |
#ifdef Py_BUILD_CORE |
| 168 |
|
| 169 |
|
| 170 |
#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType) |
| 171 |
#define PyDate_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateType) |
| 172 |
|
| 173 |
#define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType) |
| 174 |
#define PyDateTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateTimeType) |
| 175 |
|
| 176 |
#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType) |
| 177 |
#define PyTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TimeType) |
| 178 |
|
| 179 |
#define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType) |
| 180 |
#define PyDelta_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DeltaType) |
| 181 |
|
| 182 |
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType) |
| 183 |
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TZInfoType) |
| 184 |
|
| 185 |
#else |
| 186 |
|
| 187 |
|
| 188 |
static PyDateTime_CAPI *PyDateTimeAPI = NULL; |
| 189 |
|
| 190 |
#define PyDateTime_IMPORT \ |
| 191 |
PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0) |
| 192 |
|
| 193 |
|
| 194 |
#define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType) |
| 195 |
#define PyDate_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateType) |
| 196 |
|
| 197 |
#define PyDateTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateTimeType) |
| 198 |
#define PyDateTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateTimeType) |
| 199 |
|
| 200 |
#define PyTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TimeType) |
| 201 |
#define PyTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TimeType) |
| 202 |
|
| 203 |
#define PyDelta_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DeltaType) |
| 204 |
#define PyDelta_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DeltaType) |
| 205 |
|
| 206 |
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType) |
| 207 |
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TZInfoType) |
| 208 |
|
| 209 |
|
| 210 |
#define PyDate_FromDate(year, month, day) \ |
| 211 |
PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType) |
| 212 |
|
| 213 |
#define PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, usec) \ |
| 214 |
PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \ |
| 215 |
min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType) |
| 216 |
|
| 217 |
#define PyTime_FromTime(hour, minute, second, usecond) \ |
| 218 |
PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \ |
| 219 |
Py_None, PyDateTimeAPI->TimeType) |
| 220 |
|
| 221 |
#define PyDelta_FromDSU(days, seconds, useconds) \ |
| 222 |
PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1, \ |
| 223 |
PyDateTimeAPI->DeltaType) |
| 224 |
|
| 225 |
|
| 226 |
#define PyDateTime_FromTimestamp(args) \ |
| 227 |
PyDateTimeAPI->DateTime_FromTimestamp( \ |
| 228 |
(PyObject*) (PyDateTimeAPI->DateTimeType), args, NULL) |
| 229 |
|
| 230 |
#define PyDate_FromTimestamp(args) \ |
| 231 |
PyDateTimeAPI->Date_FromTimestamp( \ |
| 232 |
(PyObject*) (PyDateTimeAPI->DateType), args) |
| 233 |
|
| 234 |
#endif |
| 235 |
|
| 236 |
#ifdef __cplusplus |
| 237 |
} |
| 238 |
#endif |
| 239 |
#endif |