Roundup Tracker - Issues

Message3169

Author rouilj
Recipients
Date 2003-02-23.02:08:19
Message-id
In-reply-to
Support localized date formats by:

Creating a dictionary of 
date formats. Select with
us, uk etc country code. E.G.

        
local_date_re={
            'us': ( re.compile(r'''
            
((?P<m>\d\d?)/(?P<d>\d\d?)(/(?P<y>\d\d\d\d))?)? # 
mm/dd/yyyy
            (?P<n>[. ])?                                    # . space
            
(((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d))?)?   # 
hh:mm:ss
            (?P<o>.+)?                                      # offset
        ''', re.VERBOSE), 
_("format mm/dd/yyyy not found") ),
            'uk': (re.compile(r'''
            
((?P<m>\d\d?)\.(?P<d>\d\d?)(\.(?P<y>\d\d))?)?   # 
mm.dd.yyyy
            (?P<n>[. ])?                                    # . space
            
(((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d))?)?  # 
hh:mm:ss
            (?P<o>.+)?                                     # offset
        ''', re.VERBOSE), 
_("format mm/dd/yy not found") )
        }

Each value of the 
dictionar is a list of

    [ re, "error message"]

where the 
error message is used if the pattern doesn't match.

then 
after applying the serial date regexp, but before applying the 
standard yyy-mm-dd.hh:mm:ss regexp
loop using something 
like:

       if config != None :
	    date_match_error = ''
	    for 
country in 
config.COUNTRY_DATE_FORMATS:
		m=local_date_re[country][0].match(spec)
		if 
m is not None:
		    break
		date_match_error = 
date_match_error + local_date_re[country][1]

where 
config is the tracker's self.db.config 
onject.
COUNTRY_DATE_FORMATS is in config.py and 
looks like:

     COUNTRY_DATE_FORMATS = ['us', 'uk' 
...]

So dates are first matched using serial format,
then 
matched using the COUNTRY_DATE_FORMAT table (and 
errors are generated if they don't match)
and the last format is 
roundup's standard format. This allows multiple ways of 
specifying the date format. The local_date_re could even be a 
property of the date class and be extended at the tracker level.
History
Date User Action Args
2009-02-03 14:23:38adminlinkissue691438 messages
2009-02-03 14:23:38admincreate