DateValidator

Validates that a date is within the given range. Be sure to call DateConverter first if you aren't expecting mxDateTime input.

earliest_date and latest_date may be functions; if so, they will be called each time before validating.

after_now means a time after the current timestamp; note that just a few milliseconds before now is invalid! today_or_after is more permissive, and ignores hours and minutes.

Examples:

>>> from datetime import datetime, timedelta
>>> d = DateValidator(earliest_date=datetime(2003, 1, 1))
>>> d.to_python(datetime(2004, 1, 1))
datetime.datetime(2004, 1, 1, 0, 0)
>>> d.to_python(datetime(2002, 1, 1))
Traceback (most recent call last):
    ...
Invalid: Date must be after Wednesday, 01 January 2003
>>> d.to_python(datetime(2003, 1, 1))
datetime.datetime(2003, 1, 1, 0, 0)
>>> d = DateValidator(after_now=True)
>>> now = datetime.now()
>>> d.to_python(now+timedelta(seconds=5)) == now+timedelta(seconds=5)
True
>>> d.to_python(now-timedelta(days=1))
Traceback (most recent call last):
    ...
Invalid: The date must be sometime in the future
>>> d.to_python(now+timedelta(days=1)) > now
True
>>> d = DateValidator(today_or_after=True)
>>> d.to_python(now) == now
True

Messages

after:
Date must be after %(date)s
badType:
The input must be a string (not a %(type)s: %(value)r)
before:
Date must be before %(date)s
date_format:
%%A, %%d %%B %%Y
empty:
Please enter a value
future:
The date must be sometime in the future
noneType:
The input must be a string (not None)

Attributes

a gettextargs

{}

a strip

False

a use_builtins_gettext

True

a accept_python

True

a today_or_after

False

a __singletonmethods__

('to_python', 'from_python', 'message', 'all_messages', 'subvalidators')

a declarative_count

23

a __unpackargs__

()

a after_now

False

a compound

False

a not_empty

False

a datetime_module

None

a latest_date

None

a __mutableattributes__

()

a repeating

False

a earliest_date

None

Methods

f __initargs__(self, new_attrs) ...

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

f __classinit__(cls, new_attrs) ...

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

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

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

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

See the source for more information.