jpmckinney / validictory

🎓 deprecated general purpose python data validator
Other
240 stars 57 forks source link

handling of dates fails for year 0000 #26

Closed matthiasgleichauf closed 12 years ago

matthiasgleichauf commented 12 years ago
>>> import validictory
>>> object = {'mydate': '0000-10-03T15:35:05Z'}
>>> schema = {'type': 'object', 'properties': {'mydate': {'type': 'string', 'format': 'date-time'}}}
>>> validictory.validate(object,schema)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/matze/venv/local/lib/python2.7/site-packages/validictory/__init__.py", line 28, in validate
    return v.validate(data, schema)
  File "/home/matze/venv/local/lib/python2.7/site-packages/validictory/validator.py", line 531, in validate
    self._validate(data, schema)
  File "/home/matze/venv/local/lib/python2.7/site-packages/validictory/validator.py", line 534, in _validate
    self.__validate("_data", {"_data": data}, schema)
  File "/home/matze/venv/local/lib/python2.7/site-packages/validictory/validator.py", line 563, in __validate
    newschema.get(schemaprop))
  File "/home/matze/venv/local/lib/python2.7/site-packages/validictory/validator.py", line 191, in validate_properties
    properties.get(eachProp))
  File "/home/matze/venv/local/lib/python2.7/site-packages/validictory/validator.py", line 563, in __validate
    newschema.get(schemaprop))
  File "/home/matze/venv/local/lib/python2.7/site-packages/validictory/validator.py", line 427, in validate_format
    format_validator(self, fieldname, value, format_option)
  File "/home/matze/venv/local/lib/python2.7/site-packages/validictory/validator.py", line 37, in validate_format_datetime
    "'%(format_option)s' format" % locals())
validictory.validator.ValidationError: Value '0000-10-03T15:35:05Z' of field 'mydate' is not in 'date-time' format
>>> 

fails with: validictory.validator.ValidationError: Value '0000-10-03T15:35:05Z' of field 'mydate' is not in 'date-time' format

which I believe is a bug.

Environment: python 2.7 from ubuntu-sources (12.04) validictory 0.8.3 installed via pip

jamesturk commented 12 years ago

sorry, 0000-10-03 isn't a valid python datetime, mainly because there wasn't a year zero: http://en.wikipedia.org/wiki/0_(year)