[Python-checkins] python/nondist/sandbox/datetime datetime.c,1.65,1.66 obj_datetimetz.c,1.2,1.3 test_both.py,1.70,1.71

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月13日 09:20:39 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv502
Modified Files:
	datetime.c obj_datetimetz.c test_both.py 
Log Message:
Exposed the fledgling datetimetz type, gave it a proper constructor and
destructor, gave it accessor properties, and a trivial test.
Index: datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -C2 -d -r1.65 -r1.66
*** datetime.c	13 Dec 2002 16:43:11 -0000	1.65
--- datetime.c	13 Dec 2002 17:20:24 -0000	1.66
***************
*** 1243,1246 ****
--- 1243,1249 ----
 	PyModule_AddObject(m, "timetz", (PyObject *) &PyDateTime_TimeTZType);
 
+ 	Py_INCREF(&PyDateTime_DateTimeTZType);
+ 	PyModule_AddObject(m, "datetimetz",
+ 			 (PyObject *)&PyDateTime_DateTimeTZType);
 
 	/* A 4-year cycle has an extra leap day over what we'd get from
Index: obj_datetimetz.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetimetz.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** obj_datetimetz.c	13 Dec 2002 16:43:24 -0000	1.2
--- obj_datetimetz.c	13 Dec 2002 17:20:27 -0000	1.3
***************
*** 6,40 ****
 */
 
! /* Accessor properties. */
! 
! static PyObject *
! datetimetz_hour(PyDateTime_DateTimeTZ *self, void *unused)
! {
! 	return PyInt_FromLong(DATE_GET_HOUR(self));
! }
! 
! static PyObject *
! datetimetz_minute(PyDateTime_DateTimeTZ *self, void *unused)
! {
! 	return PyInt_FromLong(DATE_GET_MINUTE(self));
! }
! 
! static PyObject *
! datetimetz_second(PyDateTime_DateTimeTZ *self, void *unused)
! {
! 	return PyInt_FromLong(DATE_GET_SECOND(self));
! }
 
 static PyObject *
! datetimetz_microsecond(PyDateTime_DateTimeTZ *self, void *unused)
 {
! 	return PyInt_FromLong(DATE_GET_MICROSECOND(self));
 }
- 
 static PyGetSetDef datetimetz_getset[] = {
! 	{"hour", (getter)datetimetz_hour},
! 	{"minute", (getter)datetimetz_minute},
! 	{"second", (getter)datetimetz_second},
! 	{"microsecond", (getter)datetimetz_microsecond},
 	{NULL}
 };
--- 6,21 ----
 */
 
! /* Accessor properties. Properties for day, month, year, hour, minute,
! * second and microsecond are inherited from datetime.
! */
 
 static PyObject *
! datetimetz_tzinfo(PyDateTime_DateTimeTZ *self, void *unused)
 {
! 	Py_INCREF(self->tzinfo);
! 	return self->tzinfo;
 }
 static PyGetSetDef datetimetz_getset[] = {
! 	{"tzinfo", (getter)datetimetz_tzinfo},
 	{NULL}
 };
***************
*** 53,76 ****
 	long second = 0;
 	long usecond = 0;
 
 	static char *keywords[] = {
 		"year", "month", "day", "hour", "minute", "second",
! 		"microsecond", NULL
 	};
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "lll|llll", keywords,
 					&year, &month, &day, &hour, &minute,
! 					&second, &usecond)) {
 		if (check_date_args(year, month, day) < 0)
 			return NULL;
 		if (check_time_args(hour, minute, second, usecond) < 0)
 			return NULL;
! 		self = new_datetime(year, month, day, hour, minute, second,
! 				 usecond);
 	}
 	return self;
 }
 
- 
 /* TM_FUNC is the shared type of localtime() and gmtime(). */
 typedef struct tm *(*TM_FUNC)(const time_t *timer);
--- 34,58 ----
 	long second = 0;
 	long usecond = 0;
+ 	PyObject *tzinfo = Py_None;
 
 	static char *keywords[] = {
 		"year", "month", "day", "hour", "minute", "second",
! 		"microsecond", "tzinfo", NULL
 	};
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "lll|llllO", keywords,
 					&year, &month, &day, &hour, &minute,
! 					&second, &usecond, &tzinfo)) {
 		if (check_date_args(year, month, day) < 0)
 			return NULL;
 		if (check_time_args(hour, minute, second, usecond) < 0)
 			return NULL;
! 		self = new_datetimetz(year, month, day,
! 				 hour, minute, second, usecond,
! 				 tzinfo);
 	}
 	return self;
 }
 
 /* TM_FUNC is the shared type of localtime() and gmtime(). */
 typedef struct tm *(*TM_FUNC)(const time_t *timer);
***************
*** 223,227 ****
 }
 
! /* datetime arithmetic. */
 
 static PyObject *
--- 205,218 ----
 }
 
! /* Destructor. */
! 
! static void
! datetimetz_dealloc(PyDateTime_DateTimeTZ *self)
! {
! 	Py_XDECREF(self->tzinfo);
! 	self->ob_type->tp_free((PyObject *)self);
! }
! 
! /* datetimetz arithmetic. */
 
 static PyObject *
***************
*** 630,634 ****
 	sizeof(PyDateTime_DateTimeTZ),		/* tp_basicsize */
 	0,					/* tp_itemsize */
! 	(destructor)PyObject_Del,		/* tp_dealloc */
 	0,					/* tp_print */
 	0,					/* tp_getattr */
--- 621,625 ----
 	sizeof(PyDateTime_DateTimeTZ),		/* tp_basicsize */
 	0,					/* tp_itemsize */
! 	(destructor)datetimetz_dealloc,		/* tp_dealloc */
 	0,					/* tp_print */
 	0,					/* tp_getattr */
Index: test_both.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_both.py,v
retrieving revision 1.70
retrieving revision 1.71
diff -C2 -d -r1.70 -r1.71
*** test_both.py	12 Dec 2002 23:04:14 -0000	1.70
--- test_both.py	13 Dec 2002 17:20:29 -0000	1.71
***************
*** 43,46 ****
--- 43,47 ----
 tzinfo = datetime.tzinfo
 timetz = datetime.timetz
+ datetimetz = datetime.datetimetz
 MINYEAR = datetime.MINYEAR
 MAXYEAR = datetime.MAXYEAR
***************
*** 1663,1666 ****
--- 1664,1683 ----
 self.assertRaises(ValueError, lambda: bool(t))
 
+ # XXX Derive this from TestDateTime.
+ class TestDateTimeTZ(unittest.TestCase):
+ 
+ theclass = datetimetz
+ 
+ def test_trivial(self):
+ dt = self.theclass(1, 2, 3, 4, 5, 6, 7)
+ self.assertEqual(dt.year, 1)
+ self.assertEqual(dt.month, 2)
+ self.assertEqual(dt.day, 3)
+ self.assertEqual(dt.hour, 4)
+ self.assertEqual(dt.minute, 5)
+ self.assertEqual(dt.second, 6)
+ self.assertEqual(dt.microsecond, 7)
+ self.assertEqual(dt.tzinfo, None)
+ 
 def test_suite():
 allsuites = [unittest.makeSuite(klass, 'test')
***************
*** 1673,1676 ****
--- 1690,1694 ----
 TestTime,
 TestTimeTZ,
+ TestDateTimeTZ,
 )
 ]

AltStyle によって変換されたページ (->オリジナル) /