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

Andreas Jung andreas at andreas-jung.com
Tue Mar 2 10:44:53 EST 2004


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

Modified Files:
	DateTime.py 
Log Message:
The DateTime module did not care about the 'datetime-format'
settings from zope.conf. Because getConfiguration().datetime_format
can be expensive we provide a method getDefaultDateFormat() that
cache the value once retrieved from the configuration machinery.
Ugly (as the DateTime module) but it works.


=== Zope/lib/python/DateTime/DateTime.py 1.97 => 1.98 ===
--- Zope/lib/python/DateTime/DateTime.py:1.97	Thu Jan  1 13:03:22 2004
+++ Zope/lib/python/DateTime/DateTime.py	Tue Mar  2 10:44:52 2004
@@ -20,6 +20,22 @@
 from time import daylight, timezone, altzone, strftime
 from types import InstanceType, IntType, FloatType, StringType, UnicodeType
 
+from App.config import getConfiguration
+
+default_datefmt = None
+
+def getDefaultDateFormat():
+    global default_datefmt
+    if default_datefmt is None:
+        try:
+            default_datefmt = getConfiguration().datetime_format
+            return default_datefmt
+        except:
+            return 'us'
+    else:
+        return default_datefmt
+
+
 try:
     from time import tzname
 except:
@@ -37,9 +53,6 @@
 class TimeError( DateTimeError ):
     pass
 
-_default_datefmt = os.environ.get('DATETIME_FORMAT', "us").lower()
-if not _default_datefmt in ('us', 'international'):
-    raise ValueError, "DATETIME_FORMAT must be either 'us' or 'international'"
 
 # To control rounding errors, we round system time to the nearest
 # millisecond.  Then delicate calculations can rely on that the
@@ -648,9 +661,8 @@
         timezones recognized by the DateTime module. Recognition of
         timezone names is case-insensitive.""" #'
 
-        datefmt = kw.get('datefmt', _default_datefmt)
-        assert datefmt in ('us', 'international')
-
+        datefmt = kw.get('datefmt', getDefaultDateFormat())
+        print datefmt
         d=t=s=None
         ac=len(args)
         millisecs = None
@@ -899,7 +911,7 @@
         tz = self.localZone(ltm)
         return tz
 
-    def _parse(self,st, datefmt=_default_datefmt):
+    def _parse(self,st, datefmt=getDefaultDateFormat()):
         # Parse date-time components from a string
         month=year=tz=tm=None
         spaces        =self.space_chars




More information about the Zope-Checkins mailing list