Skip to content
Snippets Groups Projects
Commit 4c8c7224 authored by Olivier Dony's avatar Olivier Dony
Browse files

[IMP] fields.Date[Time]: convert_to_cache: avoid costly parsing when not validating

The extra parsing check is not necessary when we're
not validating inputs, because in that case the
values come from the database and are valid.
The validation is quite expensive due to calls
to strptime() + strftime().
parent 2bbff576
No related branches found
No related tags found
No related merge requests found
......@@ -1041,8 +1041,11 @@ class Date(Field):
if not value:
return False
if isinstance(value, basestring):
value = self.from_string(value)
return value.strftime(DATE_FORMAT)
if validate:
# force parsing for validation
self.from_string(value)
return value[:DATE_LENGTH]
return self.to_string(value)
def convert_to_export(self, value, env):
if value and env.context.get('export_raw_data'):
......@@ -1106,8 +1109,14 @@ class Datetime(Field):
if not value:
return False
if isinstance(value, basestring):
value = self.from_string(value)
return value.strftime(DATETIME_FORMAT)
if validate:
# force parsing for validation
self.from_string(value)
value = value[:DATETIME_LENGTH]
if len(value) == DATE_LENGTH:
value += " 00:00:00"
return value
return self.to_string(value)
def convert_to_export(self, value, env):
if value and env.context.get('export_raw_data'):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment