Skip to content

Commit 2a799bf

Browse files
committed
datetime escapes the sandbox. The Windows build is all set. I leave it
to others to argue about how to build it on other platforms (on Windows it's in its own DLL).
1 parent 786ddb2 commit 2a799bf

8 files changed

Lines changed: 7456 additions & 1 deletion

File tree

Include/datetime.h

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/* datetime.h
2+
*/
3+
4+
#ifndef DATETIME_H
5+
#define DATETIME_H
6+
7+
/* Fields are packed into successive bytes, each viewed as unsigned and
8+
* big-endian, unless otherwise noted:
9+
*
10+
* byte offset
11+
* 0 year 2 bytes, 1-9999
12+
* 2 month 1 byte, 1-12
13+
* 3 day 1 byte, 1-31
14+
* 4 hour 1 byte, 0-23
15+
* 5 minute 1 byte, 0-59
16+
* 6 second 1 byte, 0-59
17+
* 7 usecond 3 bytes, 0-999999
18+
* 10
19+
*/
20+
21+
/* # of bytes for year, month, and day. */
22+
#define _PyDateTime_DATE_DATASIZE 4
23+
24+
/* # of bytes for hour, minute, second, and usecond. */
25+
#define _PyDateTime_TIME_DATASIZE 6
26+
27+
/* # of bytes for year, month, day, hour, minute, second, and usecond. */
28+
#define _PyDateTime_DATETIME_DATASIZE 10
29+
30+
typedef struct
31+
{
32+
PyObject_HEAD
33+
long hashcode;
34+
unsigned char data[_PyDateTime_DATE_DATASIZE];
35+
} PyDateTime_Date;
36+
37+
typedef struct
38+
{
39+
PyObject_HEAD
40+
long hashcode;
41+
unsigned char data[_PyDateTime_DATETIME_DATASIZE];
42+
} PyDateTime_DateTime;
43+
44+
typedef struct
45+
{
46+
PyObject_HEAD
47+
long hashcode;
48+
unsigned char data[_PyDateTime_DATETIME_DATASIZE];
49+
PyObject *tzinfo;
50+
} PyDateTime_DateTimeTZ;
51+
52+
typedef struct
53+
{
54+
PyObject_HEAD
55+
long hashcode;
56+
unsigned char data[_PyDateTime_TIME_DATASIZE];
57+
} PyDateTime_Time;
58+
59+
typedef struct
60+
{
61+
PyObject_HEAD
62+
long hashcode;
63+
unsigned char data[_PyDateTime_TIME_DATASIZE];
64+
PyObject *tzinfo;
65+
} PyDateTime_TimeTZ;
66+
67+
typedef struct
68+
{
69+
PyObject_HEAD
70+
long hashcode; /* -1 when unknown */
71+
int days; /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
72+
int seconds; /* 0 <= seconds < 24*3600 is invariant */
73+
int microseconds; /* 0 <= microseconds < 1000000 is invariant */
74+
} PyDateTime_Delta;
75+
76+
typedef struct
77+
{
78+
PyObject_HEAD /* a pure abstract base clase */
79+
} PyDateTime_TZInfo;
80+
81+
/* Apply for date, datetime, and datetimetz instances. */
82+
#define PyDateTime_GET_YEAR(o) ((((PyDateTime_Date*)o)->data[0] << 8) | \
83+
((PyDateTime_Date*)o)->data[1])
84+
#define PyDateTime_GET_MONTH(o) (((PyDateTime_Date*)o)->data[2])
85+
#define PyDateTime_GET_DAY(o) (((PyDateTime_Date*)o)->data[3])
86+
87+
#define PyDateTime_DATE_GET_HOUR(o) (((PyDateTime_DateTime*)o)->data[4])
88+
#define PyDateTime_DATE_GET_MINUTE(o) (((PyDateTime_DateTime*)o)->data[5])
89+
#define PyDateTime_DATE_GET_SECOND(o) (((PyDateTime_DateTime*)o)->data[6])
90+
#define PyDateTime_DATE_GET_MICROSECOND(o) \
91+
((((PyDateTime_DateTime*)o)->data[7] << 16) | \
92+
(((PyDateTime_DateTime*)o)->data[8] << 8) | \
93+
((PyDateTime_DateTime*)o)->data[9])
94+
95+
/* Apply for time and timetz instances. */
96+
#define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)o)->data[0])
97+
#define PyDateTime_TIME_GET_MINUTE(o) (((PyDateTime_Time*)o)->data[1])
98+
#define PyDateTime_TIME_GET_SECOND(o) (((PyDateTime_Time*)o)->data[2])
99+
#define PyDateTime_TIME_GET_MICROSECOND(o) \
100+
((((PyDateTime_Time*)o)->data[3] << 16) | \
101+
(((PyDateTime_Time*)o)->data[4] << 8) | \
102+
((PyDateTime_Time*)o)->data[5])
103+
104+
#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType)
105+
#define PyDate_CheckExact(op) ((op)->ob_type == &PyDateTime_DateType)
106+
107+
#define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType)
108+
#define PyDateTime_CheckExact(op) ((op)->ob_type == &PyDateTime_DateTimeType)
109+
110+
#define PyDateTimeTZ_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeTZType)
111+
#define PyDateTimeTZ_CheckExact(op) ((op)->ob_type == &PyDateTime_DateTimeTZType)
112+
113+
#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType)
114+
#define PyTime_CheckExact(op) ((op)->ob_type == &PyDateTime_TimeType)
115+
116+
#define PyTimeTZ_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeTZType)
117+
#define PyTimeTZ_CheckExact(op) ((op)->ob_type == &PyDateTime_TimeTZType)
118+
119+
#define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType)
120+
#define PyDelta_CheckExact(op) ((op)->ob_type == &PyDateTime_DeltaType)
121+
122+
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType)
123+
#define PyTZInfo_CheckExact(op) ((op)->ob_type == &PyDateTime_TZInfoType)
124+
125+
#endif

0 commit comments

Comments
 (0)