7 /* Fields are packed into successive bytes, each viewed as unsigned and
8 * big-endian, unless otherwise noted:
11 * 0 year 2 bytes, 1-9999
12 * 2 month 1 byte, 1-12
15 * 5 minute 1 byte, 0-59
16 * 6 second 1 byte, 0-59
17 * 7 usecond 3 bytes, 0-999999
21 /* # of bytes for year, month, and day. */
22 #define _PyDateTime_DATE_DATASIZE 4
24 /* # of bytes for hour, minute, second, and usecond. */
25 #define _PyDateTime_TIME_DATASIZE 6
27 /* # of bytes for year, month, day, hour, minute, second, and usecond. */
28 #define _PyDateTime_DATETIME_DATASIZE 10
34 long hashcode
; /* -1 when unknown */
35 int days
; /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
36 int seconds
; /* 0 <= seconds < 24*3600 is invariant */
37 int microseconds
; /* 0 <= microseconds < 1000000 is invariant */
42 PyObject_HEAD
/* a pure abstract base clase */
46 /* The datetime and time types have hashcodes, and an optional tzinfo member,
47 * present if and only if hastzinfo is true.
49 #define _PyTZINFO_HEAD \
52 char hastzinfo; /* boolean flag */
54 /* No _PyDateTime_BaseTZInfo is allocated; it's just to have something
55 * convenient to cast to, when getting at the hastzinfo member of objects
56 * starting with _PyTZINFO_HEAD.
61 } _PyDateTime_BaseTZInfo
;
63 /* All time objects are of PyDateTime_TimeType, but that can be allocated
64 * in two ways, with or without a tzinfo member. Without is the same as
65 * tzinfo == None, but consumes less memory. _PyDateTime_BaseTime is an
66 * internal struct used to allocate the right amount of space for the
69 #define _PyDateTime_TIMEHEAD \
71 unsigned char data[_PyDateTime_TIME_DATASIZE];
76 } _PyDateTime_BaseTime
; /* hastzinfo false */
82 } PyDateTime_Time
; /* hastzinfo true */
85 /* All datetime objects are of PyDateTime_DateTimeType, but that can be
86 * allocated in two ways too, just like for time objects above. In addition,
87 * the plain date type is a base class for datetime, so it must also have
88 * a hastzinfo member (although it's unused there).
93 unsigned char data
[_PyDateTime_DATE_DATASIZE
];
96 #define _PyDateTime_DATETIMEHEAD \
98 unsigned char data[_PyDateTime_DATETIME_DATASIZE];
102 _PyDateTime_DATETIMEHEAD
103 } _PyDateTime_BaseDateTime
; /* hastzinfo false */
107 _PyDateTime_DATETIMEHEAD
109 } PyDateTime_DateTime
; /* hastzinfo true */
112 /* Apply for date and datetime instances. */
113 #define PyDateTime_GET_YEAR(o) ((((PyDateTime_Date*)o)->data[0] << 8) | \
114 ((PyDateTime_Date*)o)->data[1])
115 #define PyDateTime_GET_MONTH(o) (((PyDateTime_Date*)o)->data[2])
116 #define PyDateTime_GET_DAY(o) (((PyDateTime_Date*)o)->data[3])
118 #define PyDateTime_DATE_GET_HOUR(o) (((PyDateTime_DateTime*)o)->data[4])
119 #define PyDateTime_DATE_GET_MINUTE(o) (((PyDateTime_DateTime*)o)->data[5])
120 #define PyDateTime_DATE_GET_SECOND(o) (((PyDateTime_DateTime*)o)->data[6])
121 #define PyDateTime_DATE_GET_MICROSECOND(o) \
122 ((((PyDateTime_DateTime*)o)->data[7] << 16) | \
123 (((PyDateTime_DateTime*)o)->data[8] << 8) | \
124 ((PyDateTime_DateTime*)o)->data[9])
126 /* Apply for time instances. */
127 #define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)o)->data[0])
128 #define PyDateTime_TIME_GET_MINUTE(o) (((PyDateTime_Time*)o)->data[1])
129 #define PyDateTime_TIME_GET_SECOND(o) (((PyDateTime_Time*)o)->data[2])
130 #define PyDateTime_TIME_GET_MICROSECOND(o) \
131 ((((PyDateTime_Time*)o)->data[3] << 16) | \
132 (((PyDateTime_Time*)o)->data[4] << 8) | \
133 ((PyDateTime_Time*)o)->data[5])
135 #define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType)
136 #define PyDate_CheckExact(op) ((op)->ob_type == &PyDateTime_DateType)
138 #define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType)
139 #define PyDateTime_CheckExact(op) ((op)->ob_type == &PyDateTime_DateTimeType)
141 #define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType)
142 #define PyTime_CheckExact(op) ((op)->ob_type == &PyDateTime_TimeType)
144 #define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType)
145 #define PyDelta_CheckExact(op) ((op)->ob_type == &PyDateTime_DeltaType)
147 #define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType)
148 #define PyTZInfo_CheckExact(op) ((op)->ob_type == &PyDateTime_TZInfoType)