[Zope3-checkins] CVS: Zope3/lib/python/datetime - _datetime.py:1.6 test_datetime.py:1.6

Marius Gedminas mgedmin@codeworks.lt
Thu, 21 Nov 2002 05:42:37 -0500


Update of /cvs-repository/Zope3/lib/python/datetime
In directory cvs.zope.org:/tmp/cvs-serv8141

Modified Files:
	_datetime.py test_datetime.py 
Log Message:
The timetuple() bug was fixed (in a much nicer way) in the master copy from
Python 2.3 CVS.  This commit just resyncs the tests with the master copy (I've
checked that the new test_timetuple catches my bug).  I also had to copy the
working definition of _yday to make the new test pass.  After this,
_datetime.py becomes identical to the master copy, and test_datetime.py differs
only in import statements.



=== Zope3/lib/python/datetime/_datetime.py 1.5 => 1.6 ===
--- Zope3/lib/python/datetime/_datetime.py:1.5	Tue Nov 19 12:50:49 2002
+++ Zope3/lib/python/datetime/_datetime.py	Thu Nov 21 05:42:35 2002
@@ -558,11 +558,8 @@
     # Standard conversions, __cmp__, __hash__ (and helpers)
 
     def _yday(self):
-        """Return tm_yday: day within the current year, where Jan 1 == 1.
-
-        XXX This is not correct for now.  Who cares.
-        """
-        return 0
+        "Return tm_yday: day within the current year, where Jan 1 == 1."
+        return _days_before_month(self.__month, self.__year) + self.__day
 
     def timetuple(self):
         "Return local time tuple compatible with time.localtime()."


=== Zope3/lib/python/datetime/test_datetime.py 1.5 => 1.6 ===
--- Zope3/lib/python/datetime/test_datetime.py:1.5	Thu Nov 21 05:26:53 2002
+++ Zope3/lib/python/datetime/test_datetime.py	Thu Nov 21 05:42:35 2002
@@ -291,20 +291,6 @@
         t = self.theclass(2, 3, 2)
         self.assertEqual(t.isoformat(), "0002-03-02")
 
-    def test_strftime(self):
-        # If t.strftime uses time.localtime instead of time.gmtime while west
-        # from GMT, the date will be incorrect.  If that happens east from GMT,
-        # the time will be nonzero.  If we test in GMT, we won't notice the bug.
-        t = self.theclass(2002, 3, 4)
-        self.assertEqual(t.strftime('%Y-%m-%d %H:%M:%S'), "2002-03-04 00:00:00")
-
-    def test_timetuple(self):
-        # If t.timetuple uses time.localtime instead of time.gmtime while west
-        # from GMT, the date will be incorrect.  If that happens east from GMT,
-        # the time will be nonzero.  If we test in GMT, we won't notice the bug.
-        t = self.theclass(2002, 3, 4)
-        self.assertEqual(t.timetuple()[:6], (2002, 3, 4, 0, 0, 0))
-
     def test_ctime(self):
         t = self.theclass(2002, 3, 2)
         self.assertEqual(t.ctime(), "Sat Mar  2 00:00:00 2002")
@@ -325,6 +311,21 @@
         self.assertEqual(self.theclass.min + big, self.theclass.max)
         self.assertEqual(self.theclass.max - big, self.theclass.min)
 
+    def test_timetuple(self):
+        for i in range(7):
+            # January 2, 1956 is a Monday (0)
+            d = self.theclass(1956, 1, 2+i)
+            t = d.timetuple()
+            self.assertEqual(t, (1956, 1, 2+i, 0, 0, 0, i, 2+i, -1))
+            # February 1, 1956 is a Wednesday (2)
+            d = self.theclass(1956, 2, 1+i)
+            t = d.timetuple()
+            self.assertEqual(t, (1956, 2, 1+i, 0, 0, 0, (2+i)%7, 32+i, -1))
+            # March 1, 1956 is a Thursday (3), and is the 31+29+1 = 61st day
+            # of the year.
+            d = self.theclass(1956, 3, 1+i)
+            t = d.timetuple()
+            self.assertEqual(t, (1956, 3, 1+i, 0, 0, 0, (3+i)%7, 61+i, -1))
 
 class TestDateTime(TestDate):