[Python-checkins] python/nondist/sandbox/datetime obj_timetz.c,1.14,1.15 test_both.py,1.62,1.63 test_datetime.py,1.63,1.64

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月11日 18:19:46 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv30008
Modified Files:
	obj_timetz.c test_both.py test_datetime.py 
Log Message:
Repaired timetz_hash().
Index: obj_timetz.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_timetz.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** obj_timetz.c	12 Dec 2002 01:57:00 -0000	1.14
--- obj_timetz.c	12 Dec 2002 02:19:43 -0000	1.15
***************
*** 226,229 ****
--- 226,230 ----
 	long offset;
 	int none;
+ 	long minutes;
 
 	if (self->hashcode != -1)
***************
*** 240,250 ****
 		goto Done;
 	}
! 	if (none)	/* utcoffset returned None */
 		goto Done;
 
! 	/* It doesn't really matter what we do now. Scrambling the bits
! 	 * a little based on the offset is as good as anything.
 	 */
! 	self->hashcode ^= offset * 1319;
 	if (self->hashcode == -1)
 		self->hashcode = -2;
--- 241,259 ----
 		goto Done;
 	}
! 	if (none)
 		goto Done;
 
! 	/* It doesn't really matter what we do now, except that we have to
! 	 * ensure that timetz objects that compare equal have equal hashcodes.
! 	 * So something based on subtracting offset minutes is needed.
! 	 * CAUTION: it's not OK to return right away if offset==0: we
! 	 * need to go thru the whole business below so that, e.g., a timetz
! 	 * with hour=5 and offset=-60 gets the same hash code as a timetz
! 	 * with hour=6 and offset=0.
 	 */
! 	minutes = TIME_GET_HOUR(self) * 60L + TIME_GET_MINUTE(self) - offset;
! 	self->hashcode = minutes * 3601L + /* the multiplier is arbitrary */
! 			 TIME_GET_SECOND(self) * 61L +
! 			 TIME_GET_MICROSECOND(self);
 	if (self->hashcode == -1)
 		self->hashcode = -2;
Index: test_both.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_both.py,v
retrieving revision 1.62
retrieving revision 1.63
diff -C2 -d -r1.62 -r1.63
*** test_both.py	12 Dec 2002 01:57:00 -0000	1.62
--- test_both.py	12 Dec 2002 02:19:43 -0000	1.63
***************
*** 1493,1499 ****
 # self.assertEqual(t2.tzname(), "UTC")
 # self.assertEqual(t3.tzname(), "MET")
! # self.assertEqual(hash(t1), hash(t2))
! # self.assertEqual(hash(t1), hash(t3))
! # self.assertEqual(hash(t2), hash(t3))
 self.assertEqual(t1, t2)
 self.assertEqual(t1, t3)
--- 1493,1499 ----
 # self.assertEqual(t2.tzname(), "UTC")
 # self.assertEqual(t3.tzname(), "MET")
! self.assertEqual(hash(t1), hash(t2))
! self.assertEqual(hash(t1), hash(t3))
! self.assertEqual(hash(t2), hash(t3))
 self.assertEqual(t1, t2)
 self.assertEqual(t1, t3)
Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_datetime.py,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -d -r1.63 -r1.64
*** test_datetime.py	12 Dec 2002 01:57:00 -0000	1.63
--- test_datetime.py	12 Dec 2002 02:19:43 -0000	1.64
***************
*** 48,54 ****
 self.assertEqual(t2.tzname(), "UTC")
 self.assertEqual(t3.tzname(), "MET")
- self.assertEqual(hash(t1), hash(t2))
- self.assertEqual(hash(t1), hash(t3))
- self.assertEqual(hash(t2), hash(t3))
 self.assertEqual(t1.strftime("%H:%M:%S %Z %z"), "07:47:00 EST -0500")
 self.assertEqual(t2.strftime("%H:%M:%S %Z %z"), "12:47:00 UTC +0000")
--- 48,51 ----

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