[Zope-Checkins] SVN: Zope/trunk/ - Collector #1780: DateTime.strftime() now handles dates <= 1900 or

Andreas Jung andreas at andreas-jung.com
Wed May 18 11:21:11 EDT 2005


Log message for revision 30383:
  
        - Collector #1780: DateTime.strftime() now handles dates <= 1900 or
          >= 2038
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/DateTime/DateTime.py
  U   Zope/trunk/lib/python/DateTime/tests/testDateTime.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2005-05-18 14:02:32 UTC (rev 30382)
+++ Zope/trunk/doc/CHANGES.txt	2005-05-18 15:21:11 UTC (rev 30383)
@@ -31,6 +31,11 @@
 
     Bugs fixed
 
+      - Collector #1780: DateTime.strftime() now handles dates <= 1900 or
+        >= 2038
+
+      - Collector #1775: turning off debug mode by default
+
       - Collector #1784: fixed handling of multiple attributes in ZCTextIndex
 
       - Don't copy '.svn' directories from skeleton into an instance

Modified: Zope/trunk/lib/python/DateTime/DateTime.py
===================================================================
--- Zope/trunk/lib/python/DateTime/DateTime.py	2005-05-18 14:02:32 UTC (rev 30382)
+++ Zope/trunk/lib/python/DateTime/DateTime.py	2005-05-18 15:21:11 UTC (rev 30383)
@@ -18,6 +18,7 @@
 import re, math,  DateTimeZone
 from time import time, gmtime, localtime
 from time import daylight, timezone, altzone, strftime
+from datetime import datetime
 
 default_datefmt = None
 
@@ -1481,7 +1482,15 @@
 
     def strftime(self, format):
         # Format the date/time using the *current timezone representation*.
-        return strftime(format, safelocaltime(self.timeTime()))
+        x      = _calcDependentSecond2(self._year, self._month, self._day, 
+                 self._hour, self._minute, self._second)
+        ltz    = self._calcTimezoneName(x, 0)
+        tzdiff = _tzoffset(ltz, self._t) - _tzoffset(self._tz, self._t)
+        zself  = self + tzdiff/86400.0
+        microseconds = int((zself._second - zself._nearsec) * 1000000)
+        return datetime(zself._year, zself._month, zself._day, zself._hour,  
+               zself._minute, int(zself._nearsec), 
+               microseconds).strftime(format) 
 
     # General formats from previous DateTime
     def Date(self):

Modified: Zope/trunk/lib/python/DateTime/tests/testDateTime.py
===================================================================
--- Zope/trunk/lib/python/DateTime/tests/testDateTime.py	2005-05-18 14:02:32 UTC (rev 30382)
+++ Zope/trunk/lib/python/DateTime/tests/testDateTime.py	2005-05-18 15:21:11 UTC (rev 30383)
@@ -360,7 +360,21 @@
         dt_localstring = dt_local.strftime(format)
         self.assertEqual(dt_string, dt_localstring)
 
+    def testStrftimeFarDates(self):
+        '''Checks strftime in dates <= 1900 or >= 2038'''
+        dt = DateTime('1900/01/30')
+        self.assertEqual(dt.strftime('%d/%m/%Y'), '30/01/1900')
+        dt = DateTime('2040/01/30')
+        self.assertEqual(dt.strftime('%d/%m/%Y'), '30/01/2040')
 
+    def testZoneInFarDates(self):
+        '''Checks time zone in dates <= 1900 or >= 2038'''
+        dt1 = DateTime('2040/01/30 14:33 GMT+1')
+        dt2 = DateTime('2040/01/30 11:33 GMT-2')
+        self.assertEqual(dt1.strftime('%d/%m/%Y %H:%M'), dt2.strftime('%d/%m/%Y %H:%M'))
+
+        
+
 def test_suite():
     return unittest.makeSuite(DateTimeTests)
 



More information about the Zope-Checkins mailing list