datetime.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef DATETIME_H
  2. #define DATETIME_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* Define structure for C API. */
  7. typedef struct {
  8. /* type objects */
  9. PyTypeObject *DateType;
  10. PyTypeObject *DateTimeType;
  11. PyTypeObject *TimeType;
  12. PyTypeObject *DeltaType;
  13. PyTypeObject *TZInfoType;
  14. /* constructors */
  15. PyObject *(*Date_FromDate)(int, int, int, PyTypeObject*);
  16. PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int,
  17. PyObject*, PyTypeObject*);
  18. PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*);
  19. PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*);
  20. } PyDateTime_CAPI;
  21. PyAPI_DATA(PyDateTime_CAPI*) PyDateTimeAPI;
  22. #define PyDateTime_IMPORT \
  23. do { \
  24. if(PyDateTimeAPI==NULL) \
  25. PyDateTimeAPI = _PyDateTime_Import(); \
  26. } while (0)
  27. typedef struct {
  28. PyObject_HEAD
  29. } PyDateTime_Delta;
  30. typedef struct {
  31. PyObject_HEAD
  32. } PyDateTime_Date;
  33. typedef struct {
  34. PyObject_HEAD
  35. } PyDateTime_Time;
  36. typedef struct {
  37. PyObject_HEAD
  38. } PyDateTime_DateTime;
  39. typedef struct {
  40. PyObject_HEAD
  41. } PyDateTime_TZInfo;
  42. /* Macros for accessing constructors in a simplified fashion. */
  43. #define PyDate_FromDate(year, month, day) \
  44. PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType)
  45. #define PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, usec) \
  46. PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \
  47. min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType)
  48. #define PyTime_FromTime(hour, minute, second, usecond) \
  49. PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \
  50. Py_None, PyDateTimeAPI->TimeType)
  51. #define PyDelta_FromDSU(days, seconds, useconds) \
  52. PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1, \
  53. PyDateTimeAPI->DeltaType)
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif