alecthomas/voluptuous — pull request #105 by svisser (2014-11-30 01:40:01+00:00)
Title: Added validator for datetime strings

This commit adds a validator for date, times and datetimes.

If no format string is specified then ISO format will be used by default.

This resolves https://github.com/alecthomas/voluptuous/issues/98.

Example:

```python
>>> from voluptuous import Datetime
>>> Datetime('%Y')('2014')
'2014'
>>> Datetime('%Y')('2014-01-01')
Traceback (most recent call last):
File "", line 1, in
File "voluptuous.py", line 1498, in f
raise DatetimeInvalid(msg or 'value does not match expected format %s' % check_format)
voluptuous.DatetimeInvalid: value does not match expected format %Y
>>> Datetime('%Y')(1234567890)
Traceback (most recent call last):
File "", line 1, in
File "voluptuous.py", line 1498, in f
raise DatetimeInvalid(msg or 'value does not match expected format %s' % check_format)
voluptuous.DatetimeInvalid: value does not match expected format %Y
```

And also:

```python
>>> s = Schema({Required('a'): Datetime('%Y')})
>>> s({'a': 3})
Traceback (most recent call last):
File "", line 1, in
File "voluptuous.py", line 322, in __call__
return self._compiled([], data)
File "voluptuous.py", line 620, in validate_dict
return base_validate(path, iteritems(data), out)
File "voluptuous.py", line 456, in validate_mapping
raise MultipleInvalid(errors)
voluptuous.MultipleInvalid: value does not match expected format %Y for dictionary value @ data['a']
```