[Python-checkins] python/nondist/sandbox/datetime datetime.c,1.38,1.39 datetime.py,1.72,1.73 test_both.py,1.27,1.28

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月03日 13:42:06 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv1023
Modified Files:
	datetime.c datetime.py test_both.py 
Log Message:
Gave the timedelta class .min, .max, and .resolution attributes, like
the other classes here. Added a test case. .min and .max don't
currently make sense for the Python implementation, since that's happy
to use unbounded longs for the # of days.
Sometime last week I silently introduced the limitation that a timedelta
object must have a (after normalization) number of days expressible in
no more than 9 decimal digits (abs(timedeltaobj.days) < a billion). This
was to make the C implementation feasible with finite pain. It's a curious
consequence that -timedelta.max overflows, since we constrain the internal
microsecond and second members to be >= 0.
Index: datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** datetime.c	3 Dec 2002 19:41:54 -0000	1.38
--- datetime.c	3 Dec 2002 21:42:00 -0000	1.39
***************
*** 606,609 ****
--- 606,624 ----
 		return;
 
+ 	dt = new_delta(0, 0, 1);
+ 	if (dt == NULL || PyDict_SetItemString(d, "resolution", dt) < 0)
+ 		return;
+ 	Py_DECREF(dt);
+ 
+ 	dt = new_delta(1-TOOBIG_INPUT, 0, 0);
+ 	if (dt == NULL || PyDict_SetItemString(d, "min", dt) < 0)
+ 		return;
+ 	Py_DECREF(dt);
+ 
+ 	dt = new_delta(TOOBIG_INPUT-1, 24*3600-1, 1000000-1);
+ 	if (dt == NULL || PyDict_SetItemString(d, "max", dt) < 0)
+ 		return;
+ 	Py_DECREF(dt);
+ 
 	/* date values */
 	d = PyDateTime_DateType.tp_dict;
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.72
retrieving revision 1.73
diff -C2 -d -r1.72 -r1.73
*** datetime.py	3 Dec 2002 20:43:44 -0000	1.72
--- datetime.py	3 Dec 2002 21:42:02 -0000	1.73
***************
*** 474,477 ****
--- 474,482 ----
 self.__days, self.__seconds, self.__microseconds = tup
 
+ timedelta.min = timedelta(-999999999)
+ timedelta.max = timedelta(days=999999999, hours=23, minutes=59, seconds=59,
+ microseconds=999999)
+ timedelta.resolution = timedelta(microseconds=1)
+ 
 class date(object):
 """Concrete date type.
Index: test_both.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_both.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** test_both.py	3 Dec 2002 21:17:04 -0000	1.27
--- test_both.py	3 Dec 2002 21:42:03 -0000	1.28
***************
*** 255,258 ****
--- 255,267 ----
 self.assertEqual(td, td2)
 
+ def test_resolution_info(self):
+ self.assert_(isinstance(timedelta.min, timedelta))
+ self.assert_(isinstance(timedelta.max, timedelta))
+ self.assert_(isinstance(timedelta.resolution, timedelta))
+ self.assert_(timedelta.max > timedelta.min)
+ self.assertEqual(timedelta.min, timedelta(-999999999))
+ self.assertEqual(timedelta.max, timedelta(999999999, 24*3600-1, 1e6-1))
+ self.assertEqual(timedelta.resolution, timedelta(0, 0, 1))
+ 
 #############################################################################
 # date tests

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