File indexing completed on 2025-01-18 10:06:49
0001
0002
0003 #ifndef Py_LIMITED_API
0004 #ifndef DATETIME_H
0005 #define DATETIME_H
0006 #ifdef __cplusplus
0007 extern "C" {
0008 #endif
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #define _PyDateTime_DATE_DATASIZE 4
0026
0027
0028 #define _PyDateTime_TIME_DATASIZE 6
0029
0030
0031 #define _PyDateTime_DATETIME_DATASIZE 10
0032
0033
0034 typedef struct
0035 {
0036 PyObject_HEAD
0037 Py_hash_t hashcode;
0038 int days;
0039 int seconds;
0040 int microseconds;
0041 } PyDateTime_Delta;
0042
0043 typedef struct
0044 {
0045 PyObject_HEAD
0046 } PyDateTime_TZInfo;
0047
0048
0049
0050
0051
0052 #define _PyTZINFO_HEAD \
0053 PyObject_HEAD \
0054 Py_hash_t hashcode; \
0055 char hastzinfo;
0056
0057
0058
0059
0060
0061 typedef struct
0062 {
0063 _PyTZINFO_HEAD
0064 } _PyDateTime_BaseTZInfo;
0065
0066
0067
0068
0069
0070
0071
0072 #define _PyDateTime_TIMEHEAD \
0073 _PyTZINFO_HEAD \
0074 unsigned char data[_PyDateTime_TIME_DATASIZE];
0075
0076 typedef struct
0077 {
0078 _PyDateTime_TIMEHEAD
0079 } _PyDateTime_BaseTime;
0080
0081 typedef struct
0082 {
0083 _PyDateTime_TIMEHEAD
0084 unsigned char fold;
0085 PyObject *tzinfo;
0086 } PyDateTime_Time;
0087
0088
0089
0090
0091
0092
0093
0094 typedef struct
0095 {
0096 _PyTZINFO_HEAD
0097 unsigned char data[_PyDateTime_DATE_DATASIZE];
0098 } PyDateTime_Date;
0099
0100 #define _PyDateTime_DATETIMEHEAD \
0101 _PyTZINFO_HEAD \
0102 unsigned char data[_PyDateTime_DATETIME_DATASIZE];
0103
0104 typedef struct
0105 {
0106 _PyDateTime_DATETIMEHEAD
0107 } _PyDateTime_BaseDateTime;
0108
0109 typedef struct
0110 {
0111 _PyDateTime_DATETIMEHEAD
0112 unsigned char fold;
0113 PyObject *tzinfo;
0114 } PyDateTime_DateTime;
0115
0116
0117
0118
0119
0120 #define _PyDateTime_HAS_TZINFO(o) (((_PyDateTime_BaseTZInfo *)(o))->hastzinfo)
0121
0122 #define PyDateTime_GET_YEAR(o) ((((PyDateTime_Date*)(o))->data[0] << 8) | \
0123 ((PyDateTime_Date*)(o))->data[1])
0124 #define PyDateTime_GET_MONTH(o) (((PyDateTime_Date*)(o))->data[2])
0125 #define PyDateTime_GET_DAY(o) (((PyDateTime_Date*)(o))->data[3])
0126
0127 #define PyDateTime_DATE_GET_HOUR(o) (((PyDateTime_DateTime*)(o))->data[4])
0128 #define PyDateTime_DATE_GET_MINUTE(o) (((PyDateTime_DateTime*)(o))->data[5])
0129 #define PyDateTime_DATE_GET_SECOND(o) (((PyDateTime_DateTime*)(o))->data[6])
0130 #define PyDateTime_DATE_GET_MICROSECOND(o) \
0131 ((((PyDateTime_DateTime*)(o))->data[7] << 16) | \
0132 (((PyDateTime_DateTime*)(o))->data[8] << 8) | \
0133 ((PyDateTime_DateTime*)(o))->data[9])
0134 #define PyDateTime_DATE_GET_FOLD(o) (((PyDateTime_DateTime*)(o))->fold)
0135 #define PyDateTime_DATE_GET_TZINFO(o) (_PyDateTime_HAS_TZINFO((o)) ? \
0136 ((PyDateTime_DateTime *)(o))->tzinfo : Py_None)
0137
0138
0139 #define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)(o))->data[0])
0140 #define PyDateTime_TIME_GET_MINUTE(o) (((PyDateTime_Time*)(o))->data[1])
0141 #define PyDateTime_TIME_GET_SECOND(o) (((PyDateTime_Time*)(o))->data[2])
0142 #define PyDateTime_TIME_GET_MICROSECOND(o) \
0143 ((((PyDateTime_Time*)(o))->data[3] << 16) | \
0144 (((PyDateTime_Time*)(o))->data[4] << 8) | \
0145 ((PyDateTime_Time*)(o))->data[5])
0146 #define PyDateTime_TIME_GET_FOLD(o) (((PyDateTime_Time*)(o))->fold)
0147 #define PyDateTime_TIME_GET_TZINFO(o) (_PyDateTime_HAS_TZINFO(o) ? \
0148 ((PyDateTime_Time *)(o))->tzinfo : Py_None)
0149
0150
0151 #define PyDateTime_DELTA_GET_DAYS(o) (((PyDateTime_Delta*)(o))->days)
0152 #define PyDateTime_DELTA_GET_SECONDS(o) (((PyDateTime_Delta*)(o))->seconds)
0153 #define PyDateTime_DELTA_GET_MICROSECONDS(o) \
0154 (((PyDateTime_Delta*)(o))->microseconds)
0155
0156
0157
0158 typedef struct {
0159
0160 PyTypeObject *DateType;
0161 PyTypeObject *DateTimeType;
0162 PyTypeObject *TimeType;
0163 PyTypeObject *DeltaType;
0164 PyTypeObject *TZInfoType;
0165
0166
0167 PyObject *TimeZone_UTC;
0168
0169
0170 PyObject *(*Date_FromDate)(int, int, int, PyTypeObject*);
0171 PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int,
0172 PyObject*, PyTypeObject*);
0173 PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*);
0174 PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*);
0175 PyObject *(*TimeZone_FromTimeZone)(PyObject *offset, PyObject *name);
0176
0177
0178 PyObject *(*DateTime_FromTimestamp)(PyObject*, PyObject*, PyObject*);
0179 PyObject *(*Date_FromTimestamp)(PyObject*, PyObject*);
0180
0181
0182 PyObject *(*DateTime_FromDateAndTimeAndFold)(int, int, int, int, int, int, int,
0183 PyObject*, int, PyTypeObject*);
0184 PyObject *(*Time_FromTimeAndFold)(int, int, int, int, PyObject*, int, PyTypeObject*);
0185
0186 } PyDateTime_CAPI;
0187
0188 #define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI"
0189
0190
0191
0192
0193
0194
0195 #ifndef _PY_DATETIME_IMPL
0196
0197 static PyDateTime_CAPI *PyDateTimeAPI = NULL;
0198
0199 #define PyDateTime_IMPORT \
0200 PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)
0201
0202
0203 #define PyDateTime_TimeZone_UTC PyDateTimeAPI->TimeZone_UTC
0204
0205
0206 #define PyDate_Check(op) PyObject_TypeCheck((op), PyDateTimeAPI->DateType)
0207 #define PyDate_CheckExact(op) Py_IS_TYPE((op), PyDateTimeAPI->DateType)
0208
0209 #define PyDateTime_Check(op) PyObject_TypeCheck((op), PyDateTimeAPI->DateTimeType)
0210 #define PyDateTime_CheckExact(op) Py_IS_TYPE((op), PyDateTimeAPI->DateTimeType)
0211
0212 #define PyTime_Check(op) PyObject_TypeCheck((op), PyDateTimeAPI->TimeType)
0213 #define PyTime_CheckExact(op) Py_IS_TYPE((op), PyDateTimeAPI->TimeType)
0214
0215 #define PyDelta_Check(op) PyObject_TypeCheck((op), PyDateTimeAPI->DeltaType)
0216 #define PyDelta_CheckExact(op) Py_IS_TYPE((op), PyDateTimeAPI->DeltaType)
0217
0218 #define PyTZInfo_Check(op) PyObject_TypeCheck((op), PyDateTimeAPI->TZInfoType)
0219 #define PyTZInfo_CheckExact(op) Py_IS_TYPE((op), PyDateTimeAPI->TZInfoType)
0220
0221
0222
0223 #define PyDate_FromDate(year, month, day) \
0224 PyDateTimeAPI->Date_FromDate((year), (month), (day), PyDateTimeAPI->DateType)
0225
0226 #define PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, usec) \
0227 PyDateTimeAPI->DateTime_FromDateAndTime((year), (month), (day), (hour), \
0228 (min), (sec), (usec), Py_None, PyDateTimeAPI->DateTimeType)
0229
0230 #define PyDateTime_FromDateAndTimeAndFold(year, month, day, hour, min, sec, usec, fold) \
0231 PyDateTimeAPI->DateTime_FromDateAndTimeAndFold((year), (month), (day), (hour), \
0232 (min), (sec), (usec), Py_None, (fold), PyDateTimeAPI->DateTimeType)
0233
0234 #define PyTime_FromTime(hour, minute, second, usecond) \
0235 PyDateTimeAPI->Time_FromTime((hour), (minute), (second), (usecond), \
0236 Py_None, PyDateTimeAPI->TimeType)
0237
0238 #define PyTime_FromTimeAndFold(hour, minute, second, usecond, fold) \
0239 PyDateTimeAPI->Time_FromTimeAndFold((hour), (minute), (second), (usecond), \
0240 Py_None, (fold), PyDateTimeAPI->TimeType)
0241
0242 #define PyDelta_FromDSU(days, seconds, useconds) \
0243 PyDateTimeAPI->Delta_FromDelta((days), (seconds), (useconds), 1, \
0244 PyDateTimeAPI->DeltaType)
0245
0246 #define PyTimeZone_FromOffset(offset) \
0247 PyDateTimeAPI->TimeZone_FromTimeZone((offset), NULL)
0248
0249 #define PyTimeZone_FromOffsetAndName(offset, name) \
0250 PyDateTimeAPI->TimeZone_FromTimeZone((offset), (name))
0251
0252
0253 #define PyDateTime_FromTimestamp(args) \
0254 PyDateTimeAPI->DateTime_FromTimestamp( \
0255 (PyObject*) (PyDateTimeAPI->DateTimeType), (args), NULL)
0256
0257 #define PyDate_FromTimestamp(args) \
0258 PyDateTimeAPI->Date_FromTimestamp( \
0259 (PyObject*) (PyDateTimeAPI->DateType), (args))
0260
0261 #endif
0262
0263 #ifdef __cplusplus
0264 }
0265 #endif
0266 #endif
0267 #endif