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

Marius Gedminas mgedmin@codeworks.lt
Tue, 19 Nov 2002 04:56:22 -0500


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

Modified Files:
	_datetime.py test_datetime.py 
Log Message:
Bugfix: use gmtime instead of localtime in strftime and timetuple

=== Zope3/lib/python/datetime/_datetime.py 1.3 => 1.4 ===
--- Zope3/lib/python/datetime/_datetime.py:1.3	Thu Nov  7 09:24:58 2002
+++ Zope3/lib/python/datetime/_datetime.py	Tue Nov 19 04:56:21 2002
@@ -586,7 +586,7 @@
 
     def timetuple(self):
         "Return local time tuple compatible with time.localtime()."
-        return _time.localtime(self._mktime())
+        return _time.gmtime(self._mktime())
 
     def toordinal(self):
         """Return proleptic Gregorian ordinal for the year, month and day.
@@ -612,7 +612,7 @@
 
     # Formatting methods
 
-    # XXX These shouldn't depend on time.localtime(), because that
+    # XXX These shouldn't depend on time.gmtime(), because that
     # clips the usable dates to [1970 .. 2038).  At least ctime() is
     # easily done without using strftime() -- that's better too because
     # strftime("%c", ...) is locale specific.
@@ -623,7 +623,7 @@
 
     def strftime(self, fmt):
         "Format using strftime()."
-        return _time.strftime(fmt, _time.localtime(self._mktime()))
+        return _time.strftime(fmt, _time.gmtime(self._mktime()))
 
     # Computations
 
@@ -855,11 +855,6 @@
                      self.__microsecond))
 
     # Formatting methods
-
-    # XXX These shouldn't depend on time.localtime(), because that
-    # clips the usable dates to [1970 .. 2038).  At least ctime() is
-    # easily done without using strftime() -- that's better too because
-    # strftime("%c", ...) is locale specific.
 
     # XXX An additional question is whether ctime() should renormalize
     # to local time, or display the time as entered (which may be


=== Zope3/lib/python/datetime/test_datetime.py 1.3 => 1.4 ===
--- Zope3/lib/python/datetime/test_datetime.py:1.3	Thu Oct 17 19:08:50 2002
+++ Zope3/lib/python/datetime/test_datetime.py	Tue Nov 19 04:56:21 2002
@@ -291,6 +291,13 @@
         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_ctime(self):
         t = self.theclass(2002, 3, 2)
         self.assertEqual(t.ctime(), "Sat Mar  2 00:00:00 2002")
@@ -515,6 +522,14 @@
     def test_ctime(self):
         t = self.theclass(2002, 3, 2, 18, 3, 5, 123)
         self.assertEqual(t.ctime(), "Sat Mar  2 18:03:05 2002")
+
+    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))
+
 
 
 class FixedOffset(object):