Hi,
I'm opening this issue to ask you what's the expected format of datetimes.
|
@configure.value_deserializer(IDatetime) |
|
def datetime_converter(field, value, context=None): |
|
if not isinstance(value, str): |
|
raise ValueDeserializationError(field, value, "Not a string") |
|
return parse(value) |
If we only expect ISO-8601 I think we could consider using dateutil.parser.isoparse.
Simple benchmark (python 3.8):
$ python -m timeit -s 'from dateutil.parser import parse;' 'parse("2019-01-26T10:00:00.000001+01:00")'
5000 loops, best of 5: 79.7 usec per loop
$ python -m timeit -s 'from dateutil.parser import parse, isoparse;' 'isoparse("2019-01-26T10:00:00.000001+01:00")'
20000 loops, best of 5: 10.6 usec per loop
Also, we could consider using pendulum parser (this function returns <class 'datetime.datetime'>!):
$ python -m timeit -s 'from pendulum.parsing import parse;' 'parse("2019-01-26T10:00:00.000001+01:00")'
200000 loops, best of 5: 1.56 usec per loop
What do you think?
Hi,
I'm opening this issue to ask you what's the expected format of datetimes.
guillotina/guillotina/json/deserialize_value.py
Lines 164 to 168 in c2aba28
If we only expect ISO-8601 I think we could consider using
dateutil.parser.isoparse.Simple benchmark (python 3.8):
Also, we could consider using
pendulumparser (this function returns<class 'datetime.datetime'>!):What do you think?