[Python-checkins] python/nondist/sandbox/datetime datetime.c,1.21,1.22

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Thu, 21 Nov 2002 18:59:58 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv19481

Modified Files:
	datetime.c 
Log Message:
Added some crucial asserts from the Python version.


Index: datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** datetime.c	21 Nov 2002 23:15:43 -0000	1.21
--- datetime.c	22 Nov 2002 02:59:56 -0000	1.22
***************
*** 124,127 ****
--- 124,130 ----
  }
  
+ /* Number of days in 4, 100, and 400 year cycles.  That these have
+  * the correct values is asserted in the module init function.
+  */
  #define DI4Y	1461	/* days_before_year(5); days in 4 years */
  #define DI100Y	36524	/* days_before_year(101); days in 100 years */
***************
*** 363,365 ****
--- 366,388 ----
  	PyModule_AddObject(m, "timedelta",
  			   (PyObject *) &PyDateTime_DeltaType);
+ 
+ 
+ 	/* A 4-year cycle has an extra leap day over what we'd get from
+ 	 * pasting together 4 single years.
+ 	 */
+ 	assert(DI4Y == 4 * 365 + 1);
+ 	assert(DI4Y == days_before_year(4+1));
+ 
+ 	/* Similarly, a 400-year cycle has an extra leap day over what we'd
+ 	 * get from pasting together 4 100-year cycles.
+ 	 */
+ 	assert(DI400Y == 4 * DI100Y + 1);
+ 	assert(DI400Y == days_before_year(400+1));
+ 
+ 	/* OTOH, a 100-year cycle has one fewer leap day than we'd get from
+ 	 * pasting together 25 4-year cycles.
+ 	 */
+ 	assert(DI100Y == 25 * DI4Y - 1);
+ 	assert(DI100Y == days_before_year(100+1));
+ 
  }