Latest Version: 0.9.6.2

DateConverter

Validates and converts a string date, like mm/yy, dd/mm/yy, dd-mm-yy, etc. Using month_style you can support 'mm/dd/yyyy' or 'dd/mm/yyyy'. Only these two general styles are supported.

Accepts English month names, also abbreviated. Returns value as a datetime object (you can get mx.DateTime objects if you use datetime_module='mxDateTime'). Two year dates are assumed to be within 1950-2020, with dates from 21-49 being ambiguous and signaling an error.

Use accept_day=False if you just want a month/year (like for a credit card expiration date).

>>> d = DateConverter()
>>> d.to_python('12/3/09')
datetime.date(2009, 12, 3)
>>> d.to_python('12/3/2009')
datetime.date(2009, 12, 3)
>>> d.to_python('2/30/04')
Traceback (most recent call last):
    ...
Invalid: That month only has 29 days
>>> d.to_python('13/2/05')
Traceback (most recent call last):
    ...
Invalid: Please enter a month from 1 to 12

Messages

badFormat:
Please enter the date in the form %(format)s
badType:
The input must be a string (not a %(type)s: %(value)r)
dayRange:
That month only has %(days)i days
empty:
Please enter a value
fourDigitYear:
Please enter a four-digit year
invalidDate:
That is not a valid day (%(exception)s)
invalidDay:
Please enter a valid day
invalidYear:
Please enter a number for the year
monthRange:
Please enter a month from 1 to 12
noneType:
The input must be a string (not None)
unknownMonthName:
Unknown month name: %(month)s
wrongFormat:
Please enter the date in the form %(format)s

Attributes

a __singletonmethods__

('to_python', 'from_python')

a accept_day

True

a accept_python

True

a compound

False

a month_style

'mm/dd/yyyy'

a not_empty

False

a repeating

False

a strip

False

Methods

f __call__(self, *args, **kw) ...

f __classinit__(cls, new_attrs) ...

f __classsourcerepr__(cls, source, binding=None) ...

f __init__(self, *args, **kw) ...

f __initargs__(self, new_attrs) ...

f __sourcerepr__(self, source, binding=None) ...

f convert_day(self, value, state) ...

f convert_month(self, value, state) ...

f make_month(self, value, state) ...

f make_year(self, year, state) ...

f unconvert_day(self, value, state) ...

f unconvert_month(self, value, state) ...

See the source for more information.

Top