Skip to content

[Question] Datetime deserialization format #974

@masipcat

Description

@masipcat

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?

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions