[Zope3-checkins] SVN: Zope3/trunk/src/zope/datetime/ Merged revision 68443 from the 3.3 branch:

Dmitry Vasiliev dima at hlabs.spb.ru
Fri Jun 2 07:03:08 EDT 2006


Log message for revision 68457:
  Merged revision 68443 from the 3.3 branch:
  
  Added 'local' argument to parseDatetimetz 
  

Changed:
  U   Zope3/trunk/src/zope/datetime/__init__.py
  _U  Zope3/trunk/src/zope/datetime/tests/__init__.py
  UU  Zope3/trunk/src/zope/datetime/tests/test_datetimeparse.py
  _U  Zope3/trunk/src/zope/datetime/tests/test_standard_dates.py

-=-
Modified: Zope3/trunk/src/zope/datetime/__init__.py
===================================================================
--- Zope3/trunk/src/zope/datetime/__init__.py	2006-06-02 10:27:32 UTC (rev 68456)
+++ Zope3/trunk/src/zope/datetime/__init__.py	2006-06-02 11:03:06 UTC (rev 68457)
@@ -29,6 +29,7 @@
 except ImportError:
     tzname = ('UNKNOWN', 'UNKNOWN')
 
+
 # These are needed because the various date formats below must
 # be in english per the RFCs. That means we can't use strftime,
 # which is affected by different locale settings.
@@ -456,7 +457,7 @@
 
 class DateTimeParser:
 
-    def parse(self, arg, local=1):
+    def parse(self, arg, local=True):
         """Parse a string containing some sort of date-time data.
 
         This function returns a tuple (year, month, day, hour, minute,
@@ -637,7 +638,7 @@
         tz = self.localZone(ltm)
         return tz
 
-    def _parse(self, string, local=1):
+    def _parse(self, string, local=True):
         # Parse date-time components from a string
         month = year = tz = tm = None
         spaces         = self.space_chars
@@ -912,7 +913,7 @@
 
     def dst(self, dt):
         return None
-    
+
     def tzname(self, dt):
         return None
 
@@ -938,11 +939,15 @@
 ######################################################################
 
 from datetime import datetime as _datetime
-def parseDatetimetz(string):
-    y, mo, d, h, m, s, tz = parse(string)
+
+def parseDatetimetz(string, local=True):
+    y, mo, d, h, m, s, tz = parse(string, local)
     s, micro = divmod(s, 1.0)
     micro = round(micro * 1000000)
-    offset = _tzoffset(tz, None) / 60
+    if tz:
+        offset = _tzoffset(tz, None) / 60
+    else:
+        offset = 0
     return _datetime(y, mo, d, h, m, int(s), int(micro), tzinfo(offset))
 
 _iso_tz_re = re.compile("[-+]\d\d:\d\d$")


Property changes on: Zope3/trunk/src/zope/datetime/tests/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: Zope3/trunk/src/zope/datetime/tests/test_datetimeparse.py
===================================================================
--- Zope3/trunk/src/zope/datetime/tests/test_datetimeparse.py	2006-06-02 10:27:32 UTC (rev 68456)
+++ Zope3/trunk/src/zope/datetime/tests/test_datetimeparse.py	2006-06-02 11:03:06 UTC (rev 68457)
@@ -16,13 +16,17 @@
 $Id$
 """
 import unittest
+from time import gmtime
+from datetime import datetime
+
 from zope.datetime import parse, time, DateTimeError
+from zope.datetime import parseDatetimetz, tzinfo
+from zope.datetime import _tzoffset
 
+
 class Test(unittest.TestCase):
 
     def testParse(self):
-        from zope.datetime import parse
-
         self.assertEqual(parse('1999 12 31')[:6],
                          (1999, 12, 31, 0, 0, 0))
         self.assertEqual(parse('1999 12 31 EST'),
@@ -56,8 +60,6 @@
         self.assertEqual(parse('1999-12-31T01:02:03.456-00:30')[6], '-0030')
 
     def testTime(self):
-        from time import gmtime
-        from zope.datetime import time
         self.assertEqual(gmtime(time('1999 12 31 GMT'))[:6],
                          (1999, 12, 31, 0, 0, 0))
         self.assertEqual(gmtime(time('1999 12 31 EST'))[:6],
@@ -70,7 +72,6 @@
                          (1999, 12, 31, 0, 11, 22))
 
     def testBad(self):
-        from zope.datetime import time, DateTimeError
         self.assertRaises(DateTimeError, parse, '1999')
         self.assertRaises(DateTimeError, parse, '1999-31-12 1:2:63.456')
         self.assertRaises(DateTimeError, parse, '1999-31-13 1:2:3.456')
@@ -78,7 +79,6 @@
         self.assertRaises(DateTimeError, parse, 'April 31, 1999 1:2:3.456')
 
     def testLeap(self):
-        from zope.datetime import time, DateTimeError
         self.assertRaises(DateTimeError, parse, '1999-2-29 1:2:3.456')
         self.assertRaises(DateTimeError, parse, '1900-2-29 1:2:3.456')
         self.assertEqual(parse('2000-02-29 1:2:3')[:6],
@@ -87,17 +87,16 @@
                          (2004, 2, 29, 1, 2, 3))
 
     def test_tzoffset(self):
-        from zope.datetime import _tzoffset
         self.assertEqual(_tzoffset('-0400', None), -4*60*60)
         self.assertEqual(_tzoffset('-0030', None), -30*60)
         self.assertEqual(_tzoffset('+0200', None), 2*60*60)
         self.assertEqual(_tzoffset('EET', None), 2*60*60)
 
     def testParseDatetimetz(self):
-        from datetime import datetime
-        from zope.datetime import parseDatetimetz, tzinfo
         self.assertEqual(parseDatetimetz('1999-12-31T01:02:03.037-00:30'),
                          datetime(1999, 12, 31, 1, 2, 3, 37000, tzinfo(-30)))
+        self.assertEqual(parseDatetimetz('2003 6 4 00:00:00 ', local=False),
+                         datetime(2003, 6, 4, tzinfo=tzinfo(0)))
 
 def test_suite():
     loader=unittest.TestLoader()


Property changes on: Zope3/trunk/src/zope/datetime/tests/test_datetimeparse.py
___________________________________________________________________
Name: svn:keywords
   + Id


Property changes on: Zope3/trunk/src/zope/datetime/tests/test_standard_dates.py
___________________________________________________________________
Name: svn:keywords
   + Id



More information about the Zope3-Checkins mailing list