Commit a365eb3a authored by Andreas Jung's avatar Andreas Jung

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.
parent 1f05ec44
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""Encapsulation of date/time values""" """Encapsulation of date/time values"""
__version__='$Revision: 1.97 $'[11:-2] __version__='$Revision: 1.98 $'[11:-2]
import os, re, math, DateTimeZone import os, re, math, DateTimeZone
...@@ -20,6 +20,22 @@ from time import time, gmtime, localtime, asctime ...@@ -20,6 +20,22 @@ from time import time, gmtime, localtime, asctime
from time import daylight, timezone, altzone, strftime from time import daylight, timezone, altzone, strftime
from types import InstanceType, IntType, FloatType, StringType, UnicodeType 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: try:
from time import tzname from time import tzname
except: except:
...@@ -37,9 +53,6 @@ class DateError( DateTimeError ): ...@@ -37,9 +53,6 @@ class DateError( DateTimeError ):
class TimeError( DateTimeError ): class TimeError( DateTimeError ):
pass 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 # To control rounding errors, we round system time to the nearest
# millisecond. Then delicate calculations can rely on that the # millisecond. Then delicate calculations can rely on that the
...@@ -648,9 +661,8 @@ class DateTime: ...@@ -648,9 +661,8 @@ class DateTime:
timezones recognized by the DateTime module. Recognition of timezones recognized by the DateTime module. Recognition of
timezone names is case-insensitive.""" #' timezone names is case-insensitive.""" #'
datefmt = kw.get('datefmt', _default_datefmt) datefmt = kw.get('datefmt', getDefaultDateFormat())
assert datefmt in ('us', 'international') print datefmt
d=t=s=None d=t=s=None
ac=len(args) ac=len(args)
millisecs = None millisecs = None
...@@ -899,7 +911,7 @@ class DateTime: ...@@ -899,7 +911,7 @@ class DateTime:
tz = self.localZone(ltm) tz = self.localZone(ltm)
return tz return tz
def _parse(self,st, datefmt=_default_datefmt): def _parse(self,st, datefmt=getDefaultDateFormat()):
# Parse date-time components from a string # Parse date-time components from a string
month=year=tz=tm=None month=year=tz=tm=None
spaces =self.space_chars spaces =self.space_chars
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment