[Zope-Checkins] SVN: Zope/trunk/lib/python/DateTime/ Revert ISO8601 interpretation to previously broken behaviour (assume GMT rather than local time as per spec)

Laurence Rowe l at lrowe.co.uk
Tue Oct 30 13:45:10 EDT 2007


Log message for revision 81213:
  Revert ISO8601 interpretation to previously broken behaviour (assume GMT rather than local time as per spec)

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

-=-
Modified: Zope/trunk/lib/python/DateTime/DateTime.py
===================================================================
--- Zope/trunk/lib/python/DateTime/DateTime.py	2007-10-30 17:23:24 UTC (rev 81212)
+++ Zope/trunk/lib/python/DateTime/DateTime.py	2007-10-30 17:45:10 UTC (rev 81213)
@@ -451,6 +451,9 @@
             </PRE>
 
             See http://en.wikipedia.org/wiki/ISO_8601 for full specs.
+            
+            Note that the Zope DateTime parser assumes timezone naive ISO
+            strings to be in UTC rather than local time as specified.
 
           - If the DateTime function is invoked with a single Numeric
             argument, the number is assumed to be a floating point value
@@ -1798,14 +1801,12 @@
 
         if fields['signal'] or fields['Z']:
             tznaive = False
-            tz = 'GMT%+03d%02d' % (hour_off, min_off)
         else:
             tznaive = True
-            # Figure out what time zone it is in the local area
-            # on the given date.
-            ms = seconds - math.floor(seconds)
-            x = _calcDependentSecond2(year,month,day,hour,minute,seconds)
-            tz = self._calcTimezoneName(x, ms)
+        
+        # Differ from the specification here. To preserve backwards
+        # compatibility assume a default timezone == UTC.
+        tz = 'GMT%+03d%02d' % (hour_off, min_off)
 
         return year, month, day, hour, minute, seconds, tz, tznaive
 

Modified: Zope/trunk/lib/python/DateTime/tests/testDateTime.py
===================================================================
--- Zope/trunk/lib/python/DateTime/tests/testDateTime.py	2007-10-30 17:23:24 UTC (rev 81212)
+++ Zope/trunk/lib/python/DateTime/tests/testDateTime.py	2007-10-30 17:45:10 UTC (rev 81213)
@@ -262,21 +262,22 @@
 
     def testISO8601(self):
         # ISO8601 reference dates
-        ref0 = DateTime('2002/5/2 8:00am')
+        ref0 = DateTime('2002/5/2 8:00am GMT')
         ref1 = DateTime('2002/5/2 8:00am US/Eastern')
         ref2 = DateTime('2006/11/6 10:30')
         ref3 = DateTime('2004/06/14 14:30:15 GMT-3')
         ref4 = DateTime('2006/01/01')
-        ref5 = DateTime('2002/5/2 8:00am GMT')
 
         # Basic tests
-        # this is timezone naive and should be interpreted in the local timezone
+        # Though this is timezone naive and according to specification should
+        # be interpreted in the local timezone, to preserve backwards
+        # compatibility with previously expected behaviour.
         isoDt = DateTime('2002-05-02T08:00:00')
         self.assertEqual(ref0, isoDt)
         isoDt = DateTime('2002-05-02T08:00:00Z')
-        self.assertEqual(ref5, isoDt)
+        self.assertEqual(ref0, isoDt)
         isoDt = DateTime('2002-05-02T08:00:00+00:00')
-        self.assertEqual(ref5, isoDt)
+        self.assertEqual(ref0, isoDt)
         isoDt = DateTime('2002-05-02T08:00:00-04:00')
         self.assertEqual(ref1, isoDt)
         isoDt = DateTime('2002-05-02 08:00:00-04:00')
@@ -310,7 +311,7 @@
 
         # Bug 2191: timezones with only one digit for hour
         isoDt = DateTime('20020502T080000+0')
-        self.assertEqual(ref5, isoDt)
+        self.assertEqual(ref0, isoDt)
         isoDt = DateTime('20020502 080000-4')
         self.assertEqual(ref1, isoDt)
         isoDt = DateTime('20020502T080000-400')



More information about the Zope-Checkins mailing list