[Zope-Checkins] CVS: Zope/lib/python/DateTime - DateTime.py:1.82.8.1

Andreas Jung andreas@andreas-jung.com
Sat, 30 Nov 2002 03:37:05 -0500


Update of /cvs-repository/Zope/lib/python/DateTime
In directory cvs.zope.org:/tmp/cvs-serv25677

Modified Files:
      Tag: ajung-european-datetime-support-branch
	DateTime.py 
Log Message:
added support for consistent parsing of international dates
with days before month before years


=== Zope/lib/python/DateTime/DateTime.py 1.82 => 1.82.8.1 ===
--- Zope/lib/python/DateTime/DateTime.py:1.82	Tue Oct 29 14:08:40 2002
+++ Zope/lib/python/DateTime/DateTime.py	Sat Nov 30 03:37:04 2002
@@ -456,7 +456,7 @@
     __roles__=None
     __allow_access_to_unprotected_subobjects__=1
 
-    def __init__(self,*args):
+    def __init__(self,*args, **kw):
         """Return a new date-time object
 
         A DateTime object always maintains its value as an absolute
@@ -613,6 +613,9 @@
         timezones recognized by the DateTime module. Recognition of
         timezone names is case-insensitive.""" #'
 
+        datefmt = kw.get('datefmt', 'us')
+        assert datefmt in ('us', 'international')
+
         d=t=s=None
         ac=len(args)
         millisecs = None
@@ -656,7 +659,7 @@
                 if arg.find(' ')==-1 and arg[4]=='-':
                     yr,mo,dy,hr,mn,sc,tz=self._parse_iso8601(arg)
                 else:
-                    yr,mo,dy,hr,mn,sc,tz=self._parse(arg)
+                    yr,mo,dy,hr,mn,sc,tz=self._parse(arg, datefmt)
 
 
                 if not self._validDate(yr,mo,dy):
@@ -860,7 +863,7 @@
         tz = self.localZone(ltm)
         return tz
 
-    def _parse(self,st):
+    def _parse(self,st, datefmt="us"):
         # Parse date-time components from a string
         month=year=tz=tm=None
         spaces        =self.space_chars
@@ -987,8 +990,13 @@
                     day=ints[0]
                     month=ints[1]
                 else:
-                    day=ints[1]
-                    month=ints[0]
+                    if datefmt=="us":
+                        day=ints[1]
+                        month=ints[0]
+                    else:
+                        day=ints[0]
+                        month=ints[1]
+    
             elif ints[0] <= 12:
                 month=ints[0]
                 day=ints[1]
@@ -1681,3 +1689,4 @@
 def Timezones():
     """Return the list of recognized timezone names"""
     return _cache._zlst
+