jpmckinney / validictory

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

date-time check fails on values that pass strict_rfc3339 #98

Closed chrigrahcisco closed 8 years ago

chrigrahcisco commented 8 years ago

From what I've read JSON schema date-time should adhere to rfc3339. However, dates that pass this format check are failing validictory date-time checks. It looks like it's forcing it to only allow 2-digit microseconds where the Pyton strict_rfc3339 module doesn't care how many digits there are in that position.

Quick test code:

date = '2015-11-18T19:57:05.861Z'
import strict_rfc3339
assert strict_rfc3339.validate_rfc3339(date)

object = {'mydate': date}
schema = {'type': 'object', 'properties': {'mydate': {'type': 'string', 'format': 'date-time'}}}
import validictory
validictory.validate(object, schema)

Excecute that and the assert passes, but validictory validation fails:

validictory.validator.FieldValidationError: Value '2015-11-18T19:57:05.861Z' for field '' is not in 'date-time' format

It looks like validictory is using the following code:

datetime.strptime(value, dateformat_string)

With the following formats:

validate_format_date_time = _generate_datetime_validator('date-time', '%Y-%m-%dT%H:%M:%SZ')
validate_format_date = _generate_datetime_validator('date', '%Y-%m-%d')
validate_format_time = _generate_datetime_validator('time', '%H:%M:%S')
jamesturk commented 8 years ago

thanks for the report, I'll take a look at this next time I get a chance to work on validictory, if you do happen to have time a PR would be welcome for sure though