BritishDateField

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# The newforms library has these, but uses American style m/d/Y for two of 
# them.
BRITISH_DATE_INPUT_FORMATS = (
    '%Y-%m-%d', '%d/%m/%Y', '%d/%m/%y', # '2006-10-25', '25/10/2006', '25/10/06'
    '%b %d %Y', '%b %d, %Y',            # 'Oct 25 2006', 'Oct 25, 2006'
    '%d %b %Y', '%d %b, %Y',            # '25 Oct 2006', '25 Oct, 2006'
    '%B %d %Y', '%B %d, %Y',            # 'October 25 2006', 'October 25, 2006'
    '%d %B %Y', '%d %B, %Y',            # '25 October 2006', '25 October, 2006'
)

class BritishDateField(forms.DateField):
    def __init__(self, *args, **kwargs):
        super(BritishDateField, self).__init__(
            BRITISH_DATE_INPUT_FORMATS, *args, **kwargs
        )

Comments

whiskybar (on March 21, 2007):

Indeed!

I think the Django developers should have taken a look at wikipedia to see what formats are actually common...

I use

EURO_DATE_INPUT_FORMATS = (
    '%Y%d%m', '%y%m%d', #20070223, etc.
    '%d/%m/%Y', '%d/%m/%y', #23/02/2007, etc.
    '%d. %m. %Y', '%d. %m. %y', '%d.%m.%Y', '%d.%m.%y', #23. 02. 2007, etc.
    '%d. %m %Y', '%d.%m %Y', '%d. %m %y', '%d.%m %y', #23. 2 2007, etc.
    ) + forms.DEFAULT_DATE_INPUT_FORMATS

These are common here in my region - Czech Republic, Slovakia, Hungary, Poland, Germany, Austria, etc.

#

ubernostrum (on March 21, 2007):

For the record: locale-specific things are in the process of being broken out so you can use the bits you want; for example, fields related to US address schemes are here (and there's a corresponding uk module which seems to be under construction).

It'd be helpful if folks could submit patches for these sorts of things so they could be included in the appropriate module :)

#

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.