Roundup Tracker - Issues

Issue 691438

classification
Date format localization idea and some code
Type: rfe Severity: normal
Components: Interface Versions:
process
Status: open
:
: richard : richard, rouilj
Priority: normal :

Created on 2003-02-23 02:08 by rouilj, last changed 2003-03-17 04:51 by rouilj.

Messages
msg3169 Author: [hidden] (rouilj) Date: 2003-02-23 02:08
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.
msg3170 Author: [hidden] (rouilj) Date: 2003-03-17 04:51
Logged In: YES 
user_id=707416


See:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/56036

for 
a pure python implementation of strptime(). This would
allow specs 
like:

'%a, %d %b %Y %H:%M:%S %Z'

to parse dates 
from http headers.
The standard roundup format would be:

  
%Y-%m-%d %H:%M:%S

while the use standard (mm/dd/yyyy) 
would be:

  %D %H:%M:%S

or

  
%Y/%m/%d

etc.
History
Date User Action Args
2003-02-23 02:08:19rouiljcreate