[Python-checkins] python/nondist/sandbox/datetime datetime.c,1.58,1.59 obj_timetz.c,1.10,1.11

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月11日 17:11:11 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv11692
Modified Files:
	datetime.c obj_timetz.c 
Log Message:
Whatever. It still compiles <wink>.
Index: datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -C2 -d -r1.58 -r1.59
*** datetime.c	11 Dec 2002 21:47:38 -0000	1.58
--- datetime.c	12 Dec 2002 01:11:08 -0000	1.59
***************
*** 813,818 ****
 init_datetime(void)
 {
! 	PyObject *m;
! 	PyObject *d, *dt;
 	/* Types that use __reduce__ for pickling need to set the following
 	 * magical attr in the type dict, with a true value.
--- 813,820 ----
 init_datetime(void)
 {
! 	PyObject *m;	/* a module object */
! 	PyObject *d;	/* its dict */
! 	PyObject *x;
! 
 	/* Types that use __reduce__ for pickling need to set the following
 	 * magical attr in the type dict, with a true value.
***************
*** 842,913 ****
 		return;
 
! 	dt = new_delta(0, 0, 1, 0);
! 	if (dt == NULL || PyDict_SetItemString(d, "resolution", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
! 	dt = new_delta(-MAX_DELTA_DAYS, 0, 0, 0);
! 	if (dt == NULL || PyDict_SetItemString(d, "min", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
! 	dt = new_delta(MAX_DELTA_DAYS, 24*3600-1, 1000000-1, 0);
! 	if (dt == NULL || PyDict_SetItemString(d, "max", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
 	/* date values */
 	d = PyDateTime_DateType.tp_dict;
 
! 	dt = new_date(1, 1, 1);
! 	if (dt == NULL || PyDict_SetItemString(d, "min", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
! 	dt = new_date(MAXYEAR, 12, 31);
! 	if (dt == NULL || PyDict_SetItemString(d, "max", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
! 	dt = new_delta(1, 0, 0, 0);
! 	if (dt == NULL || PyDict_SetItemString(d, "resolution", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
 	/* datetime values */
 	d = PyDateTime_DateTimeType.tp_dict;
 
! 	dt = new_datetime(1, 1, 1, 0, 0, 0, 0);
! 	if (dt == NULL || PyDict_SetItemString(d, "min", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
! 	dt = new_datetime(MAXYEAR, 12, 31, 23, 59, 59, 999999);
! 	if (dt == NULL || PyDict_SetItemString(d, "max", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
! 	dt = new_delta(0, 0, 1, 0);
! 	if (dt == NULL || PyDict_SetItemString(d, "resolution", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
 	/* time values */
 	d = PyDateTime_TimeType.tp_dict;
 
! 	dt = new_time(0, 0, 0, 0);
! 	if (dt == NULL || PyDict_SetItemString(d, "min", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
! 	dt = new_time(23, 59, 59, 999999);
! 	if (dt == NULL || PyDict_SetItemString(d, "max", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
! 	dt = new_delta(0, 0, 1, 0);
! 	if (dt == NULL || PyDict_SetItemString(d, "resolution", dt) < 0)
 		return;
! 	Py_DECREF(dt);
 
 	Py_DECREF(safepickle);
--- 844,933 ----
 		return;
 
! 	x = new_delta(0, 0, 1, 0);
! 	if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
 		return;
! 	Py_DECREF(x);
 
! 	x = new_delta(-MAX_DELTA_DAYS, 0, 0, 0);
! 	if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
 		return;
! 	Py_DECREF(x);
 
! 	x = new_delta(MAX_DELTA_DAYS, 24*3600-1, 1000000-1, 0);
! 	if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
 		return;
! 	Py_DECREF(x);
 
 	/* date values */
 	d = PyDateTime_DateType.tp_dict;
 
! 	x = new_date(1, 1, 1);
! 	if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
 		return;
! 	Py_DECREF(x);
 
! 	x = new_date(MAXYEAR, 12, 31);
! 	if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
 		return;
! 	Py_DECREF(x);
 
! 	x = new_delta(1, 0, 0, 0);
! 	if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
 		return;
! 	Py_DECREF(x);
 
 	/* datetime values */
 	d = PyDateTime_DateTimeType.tp_dict;
 
! 	x = new_datetime(1, 1, 1, 0, 0, 0, 0);
! 	if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
 		return;
! 	Py_DECREF(x);
 
! 	x = new_datetime(MAXYEAR, 12, 31, 23, 59, 59, 999999);
! 	if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
 		return;
! 	Py_DECREF(x);
 
! 	x = new_delta(0, 0, 1, 0);
! 	if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
 		return;
! 	Py_DECREF(x);
 
 	/* time values */
 	d = PyDateTime_TimeType.tp_dict;
 
! 	x = new_time(0, 0, 0, 0);
! 	if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
 		return;
! 	Py_DECREF(x);
 
! 	x = new_time(23, 59, 59, 999999);
! 	if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
 		return;
! 	Py_DECREF(x);
 
! 	x = new_delta(0, 0, 1, 0);
! 	if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
 		return;
! 	Py_DECREF(x);
! 
! 	/* timetz values */
! 	d = PyDateTime_TimeTZType.tp_dict;
! 
! 	x = new_timetz(0, 0, 0, 0, Py_None);
! 	if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
! 		return;
! 	Py_DECREF(x);
! 
! 	x = new_timetz(23, 59, 59, 999999, Py_None);
! 	if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
! 		return;
! 	Py_DECREF(x);
! 
! 	x = new_delta(0, 0, 1, 0);
! 	if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
! 		return;
! 	Py_DECREF(x);
 
 	Py_DECREF(safepickle);
Index: obj_timetz.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_timetz.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** obj_timetz.c	11 Dec 2002 22:20:17 -0000	1.10
--- obj_timetz.c	12 Dec 2002 01:11:09 -0000	1.11
***************
*** 117,120 ****
--- 117,121 ----
 }
 
+ /* XXX This one's going to be a PITA. */
 static PyObject *
 timetz_strftime(PyDateTime_TimeTZ *self, PyObject *format)
***************
*** 144,157 ****
 timetz_richcompare(PyDateTime_TimeTZ *self, PyObject *other, int op)
 {
 	long diff;
 
 	if (!PyType_IsSubtype(other->ob_type, &PyDateTime_TimeType)) {
 		PyErr_Format(PyExc_TypeError,
! 			 "can't compare time to %s instance",
 			 other->ob_type->tp_name);
 		return NULL;
 	}
! 	diff = memcmp(self->data, ((PyDateTime_TimeTZ *)other)->data,
! 		 _PyDateTime_TIME_DATASIZE);
 	return diff_to_bool(diff, op);
 }
--- 145,219 ----
 timetz_richcompare(PyDateTime_TimeTZ *self, PyObject *other, int op)
 {
+ 	PyObject *self_tzinfo;
+ 	PyObject *other_tzinfo;
+ 	long self_offset;
+ 	long other_offset;
+ 	int self_none;
+ 	int other_none;
 	long diff;
 
 	if (!PyType_IsSubtype(other->ob_type, &PyDateTime_TimeType)) {
 		PyErr_Format(PyExc_TypeError,
! 			 "can't compare 'timetz' to '%s'",
 			 other->ob_type->tp_name);
 		return NULL;
 	}
! 
! 	self_tzinfo = self->tzinfo;
! 	other_tzinfo = PyType_IsSubtype(other->ob_type,
! 					 &PyDateTime_TimeTZType) ?
! 			((PyDateTime_TimeTZ *)other)->tzinfo :
! 			Py_None;
! 
! 	if (self_tzinfo == other_tzinfo)
! 		return time_richcompare((PyDateTime_Time *)self, other, op);
! 
! 	if (self_tzinfo == Py_None) {
! 		self_offset = 0;
! 		self_none = 1;
! 	}
! 	else {
! 		self_offset = get_utcoffset(self_tzinfo,
! 					 (PyObject *)self,
! 					 &self_none);
! 		if (self_offset == -1 && PyErr_Occurred())
! 			return NULL;
! 	}
! 
! 	if (other_tzinfo == Py_None) {
! 		other_offset = 0;
! 		other_none = 1;
! 	}
! 	else {
! 		other_offset = get_utcoffset(other_tzinfo,
! 					 (PyObject *)other,
! 					 &other_none);
! 		if (other_offset == -1 && PyErr_Occurred())
! 			return NULL;
! 	}
! 
! 	if (self_none ^ other_none) {
! 		PyErr_SetString(PyExc_TypeError,
! 				"can't compare naive and timezone-aware "
! 				"times");
! 		return NULL;
! 	}
! 
! 	if (self_offset == other_offset)
! 		return time_richcompare((PyDateTime_Time *)self, other, op);
! 
! 	/* Convert everything except microseconds to seconds. These can't
! 	 * overflow.
! 	 */
! 	self_offset = TIME_GET_HOUR(self) * 3600 +
! 		 (TIME_GET_MINUTE(self) - self_offset) * 60 +
! 		 TIME_GET_SECOND(self);
! 	other_offset = TIME_GET_HOUR(other) * 3600 +
! 		 (TIME_GET_MINUTE(other) - other_offset) * 60 +
! 		 TIME_GET_SECOND(other);
! 	diff = self_offset - other_offset;
! 	if (diff == 0)
! 		diff = TIME_GET_MICROSECOND(self) -
! 		 TIME_GET_MICROSECOND(other);
 	return diff_to_bool(diff, op);
 }

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