| |
| |
| #ifndef Py_LIMITED_API |
| #ifndef DATETIME_H |
| #define DATETIME_H |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| #define _PyDateTime_DATE_DATASIZE 4 |
|
|
| |
| #define _PyDateTime_TIME_DATASIZE 6 |
|
|
| |
| #define _PyDateTime_DATETIME_DATASIZE 10 |
|
|
|
|
| typedef struct |
| { |
| PyObject_HEAD |
| Py_hash_t hashcode; |
| int days; |
| int seconds; |
| int microseconds; |
| } PyDateTime_Delta; |
|
|
| typedef struct |
| { |
| PyObject_HEAD |
| } PyDateTime_TZInfo; |
|
|
|
|
| |
| |
| |
| #define _PyTZINFO_HEAD \ |
| PyObject_HEAD \ |
| Py_hash_t hashcode; \ |
| char hastzinfo; |
|
|
| |
| |
| |
| |
| typedef struct |
| { |
| _PyTZINFO_HEAD |
| } _PyDateTime_BaseTZInfo; |
|
|
| |
| |
| |
| |
| |
| |
| #define _PyDateTime_TIMEHEAD \ |
| _PyTZINFO_HEAD \ |
| unsigned char data[_PyDateTime_TIME_DATASIZE]; |
|
|
| typedef struct |
| { |
| _PyDateTime_TIMEHEAD |
| } _PyDateTime_BaseTime; |
|
|
| typedef struct |
| { |
| _PyDateTime_TIMEHEAD |
| unsigned char fold; |
| PyObject *tzinfo; |
| } PyDateTime_Time; |
|
|
|
|
| |
| |
| |
| |
| |
| typedef struct |
| { |
| _PyTZINFO_HEAD |
| unsigned char data[_PyDateTime_DATE_DATASIZE]; |
| } PyDateTime_Date; |
|
|
| #define _PyDateTime_DATETIMEHEAD \ |
| _PyTZINFO_HEAD \ |
| unsigned char data[_PyDateTime_DATETIME_DATASIZE]; |
|
|
| typedef struct |
| { |
| _PyDateTime_DATETIMEHEAD |
| } _PyDateTime_BaseDateTime; |
|
|
| typedef struct |
| { |
| _PyDateTime_DATETIMEHEAD |
| unsigned char fold; |
| PyObject *tzinfo; |
| } PyDateTime_DateTime; |
|
|
|
|
| |
|
|
| |
| #define _PyDateTime_HAS_TZINFO(o) (((_PyDateTime_BaseTZInfo *)(o))->hastzinfo) |
|
|
| #define PyDateTime_GET_YEAR(o) ((((PyDateTime_Date*)o)->data[0] << 8) | \ |
| ((PyDateTime_Date*)o)->data[1]) |
| #define PyDateTime_GET_MONTH(o) (((PyDateTime_Date*)o)->data[2]) |
| #define PyDateTime_GET_DAY(o) (((PyDateTime_Date*)o)->data[3]) |
|
|
| #define PyDateTime_DATE_GET_HOUR(o) (((PyDateTime_DateTime*)o)->data[4]) |
| #define PyDateTime_DATE_GET_MINUTE(o) (((PyDateTime_DateTime*)o)->data[5]) |
| #define PyDateTime_DATE_GET_SECOND(o) (((PyDateTime_DateTime*)o)->data[6]) |
| #define PyDateTime_DATE_GET_MICROSECOND(o) \ |
| ((((PyDateTime_DateTime*)o)->data[7] << 16) | \ |
| (((PyDateTime_DateTime*)o)->data[8] << 8) | \ |
| ((PyDateTime_DateTime*)o)->data[9]) |
| #define PyDateTime_DATE_GET_FOLD(o) (((PyDateTime_DateTime*)o)->fold) |
| #define PyDateTime_DATE_GET_TZINFO(o) (_PyDateTime_HAS_TZINFO(o) ? \ |
| ((PyDateTime_DateTime *)(o))->tzinfo : Py_None) |
|
|
| |
| #define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)o)->data[0]) |
| #define PyDateTime_TIME_GET_MINUTE(o) (((PyDateTime_Time*)o)->data[1]) |
| #define PyDateTime_TIME_GET_SECOND(o) (((PyDateTime_Time*)o)->data[2]) |
| #define PyDateTime_TIME_GET_MICROSECOND(o) \ |
| ((((PyDateTime_Time*)o)->data[3] << 16) | \ |
| (((PyDateTime_Time*)o)->data[4] << 8) | \ |
| ((PyDateTime_Time*)o)->data[5]) |
| #define PyDateTime_TIME_GET_FOLD(o) (((PyDateTime_Time*)o)->fold) |
| #define PyDateTime_TIME_GET_TZINFO(o) (_PyDateTime_HAS_TZINFO(o) ? \ |
| ((PyDateTime_Time *)(o))->tzinfo : Py_None) |
|
|
| |
| #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) |
|
|
|
|
| |
| typedef struct { |
| |
| PyTypeObject *DateType; |
| PyTypeObject *DateTimeType; |
| PyTypeObject *TimeType; |
| PyTypeObject *DeltaType; |
| PyTypeObject *TZInfoType; |
|
|
| |
| PyObject *TimeZone_UTC; |
|
|
| |
| PyObject *(*Date_FromDate)(int, int, int, PyTypeObject*); |
| PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int, |
| PyObject*, PyTypeObject*); |
| PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*); |
| PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*); |
| PyObject *(*TimeZone_FromTimeZone)(PyObject *offset, PyObject *name); |
|
|
| |
| PyObject *(*DateTime_FromTimestamp)(PyObject*, PyObject*, PyObject*); |
| PyObject *(*Date_FromTimestamp)(PyObject*, PyObject*); |
|
|
| |
| PyObject *(*DateTime_FromDateAndTimeAndFold)(int, int, int, int, int, int, int, |
| PyObject*, int, PyTypeObject*); |
| PyObject *(*Time_FromTimeAndFold)(int, int, int, int, PyObject*, int, PyTypeObject*); |
|
|
| } PyDateTime_CAPI; |
|
|
| #define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI" |
|
|
|
|
| |
| |
| |
| |
| #ifndef _PY_DATETIME_IMPL |
| |
| static PyDateTime_CAPI *PyDateTimeAPI = NULL; |
|
|
| #define PyDateTime_IMPORT \ |
| PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0) |
|
|
| |
| #define PyDateTime_TimeZone_UTC PyDateTimeAPI->TimeZone_UTC |
|
|
| |
| #define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType) |
| #define PyDate_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->DateType) |
|
|
| #define PyDateTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateTimeType) |
| #define PyDateTime_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->DateTimeType) |
|
|
| #define PyTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TimeType) |
| #define PyTime_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->TimeType) |
|
|
| #define PyDelta_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DeltaType) |
| #define PyDelta_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->DeltaType) |
|
|
| #define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType) |
| #define PyTZInfo_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->TZInfoType) |
|
|
|
|
| |
| #define PyDate_FromDate(year, month, day) \ |
| PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType) |
|
|
| #define PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, usec) \ |
| PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \ |
| min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType) |
|
|
| #define PyDateTime_FromDateAndTimeAndFold(year, month, day, hour, min, sec, usec, fold) \ |
| PyDateTimeAPI->DateTime_FromDateAndTimeAndFold(year, month, day, hour, \ |
| min, sec, usec, Py_None, fold, PyDateTimeAPI->DateTimeType) |
|
|
| #define PyTime_FromTime(hour, minute, second, usecond) \ |
| PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \ |
| Py_None, PyDateTimeAPI->TimeType) |
|
|
| #define PyTime_FromTimeAndFold(hour, minute, second, usecond, fold) \ |
| PyDateTimeAPI->Time_FromTimeAndFold(hour, minute, second, usecond, \ |
| Py_None, fold, PyDateTimeAPI->TimeType) |
|
|
| #define PyDelta_FromDSU(days, seconds, useconds) \ |
| PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1, \ |
| PyDateTimeAPI->DeltaType) |
|
|
| #define PyTimeZone_FromOffset(offset) \ |
| PyDateTimeAPI->TimeZone_FromTimeZone(offset, NULL) |
|
|
| #define PyTimeZone_FromOffsetAndName(offset, name) \ |
| PyDateTimeAPI->TimeZone_FromTimeZone(offset, name) |
|
|
| |
| #define PyDateTime_FromTimestamp(args) \ |
| PyDateTimeAPI->DateTime_FromTimestamp( \ |
| (PyObject*) (PyDateTimeAPI->DateTimeType), args, NULL) |
|
|
| #define PyDate_FromTimestamp(args) \ |
| PyDateTimeAPI->Date_FromTimestamp( \ |
| (PyObject*) (PyDateTimeAPI->DateType), args) |
|
|
| #endif |
|
|
| #ifdef __cplusplus |
| } |
| #endif |
| #endif |
| #endif |
|
|