Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37f3982

Browse files
committed
Got rid of the timetz type entirely. This was a bit trickier than I
hoped it would be, but not too bad. A test had to change: time.__setstate__() can no longer add a non-None tzinfo member to a time object that didn't already have one, since storage for a tzinfo member doesn't exist in that case.
1 parent a5e8bb9 commit 37f3982

3 files changed

Lines changed: 394 additions & 529 deletions

File tree

Include/datetime.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
/* # of bytes for year, month, day, hour, minute, second, and usecond. */
2828
#define _PyDateTime_DATETIME_DATASIZE 10
2929

30+
#define _PyTZINFO_HEAD \
31+
PyObject_HEAD \
32+
long hashcode; \
33+
char hastzinfo; /* boolean flag */
34+
3035
typedef struct
3136
{
3237
PyObject_HEAD
@@ -49,20 +54,23 @@ typedef struct
4954
PyObject *tzinfo;
5055
} PyDateTime_DateTimeTZ;
5156

57+
58+
59+
#define _PyDateTime_TIMEHEAD \
60+
_PyTZINFO_HEAD \
61+
unsigned char data[_PyDateTime_TIME_DATASIZE];
62+
5263
typedef struct
5364
{
54-
PyObject_HEAD
55-
long hashcode;
56-
unsigned char data[_PyDateTime_TIME_DATASIZE];
57-
} PyDateTime_Time;
65+
_PyDateTime_TIMEHEAD
66+
} _PyDateTime_BaseTime; /* hastzinfo false */
5867

5968
typedef struct
6069
{
61-
PyObject_HEAD
62-
long hashcode;
63-
unsigned char data[_PyDateTime_TIME_DATASIZE];
70+
_PyDateTime_TIMEHEAD
6471
PyObject *tzinfo;
65-
} PyDateTime_TimeTZ;
72+
} PyDateTime_Time; /* hastzinfo true */
73+
6674

6775
typedef struct
6876
{
@@ -92,7 +100,7 @@ typedef struct
92100
(((PyDateTime_DateTime*)o)->data[8] << 8) | \
93101
((PyDateTime_DateTime*)o)->data[9])
94102

95-
/* Apply for time and timetz instances. */
103+
/* Apply for time instances. */
96104
#define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)o)->data[0])
97105
#define PyDateTime_TIME_GET_MINUTE(o) (((PyDateTime_Time*)o)->data[1])
98106
#define PyDateTime_TIME_GET_SECOND(o) (((PyDateTime_Time*)o)->data[2])
@@ -113,9 +121,6 @@ typedef struct
113121
#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType)
114122
#define PyTime_CheckExact(op) ((op)->ob_type == &PyDateTime_TimeType)
115123

116-
#define PyTimeTZ_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeTZType)
117-
#define PyTimeTZ_CheckExact(op) ((op)->ob_type == &PyDateTime_TimeTZType)
118-
119124
#define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType)
120125
#define PyDelta_CheckExact(op) ((op)->ob_type == &PyDateTime_DeltaType)
121126

Lib/test/test_datetime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ def test_pickling(self):
18571857
tinfo = PicklableFixedOffset(-300, 'cookie')
18581858
orig = self.theclass(5, 6, 7, tzinfo=tinfo)
18591859
state = orig.__getstate__()
1860-
derived = self.theclass()
1860+
derived = self.theclass(tzinfo=FixedOffset(0, "UTC", 0))
18611861
derived.__setstate__(state)
18621862
self.assertEqual(orig, derived)
18631863
self.failUnless(isinstance(derived.tzinfo, PicklableFixedOffset))

0 commit comments

Comments
 (0)