in elasticsearch/dsl/field.py [0:0]
def _deserialize(self, data: Any) -> Union[datetime, date]:
if isinstance(data, str):
try:
data = parser.parse(data)
except Exception as e:
raise ValidationException(
f"Could not parse date from the value ({data!r})", e
)
# we treat the yyyy-MM-dd format as a special case
if hasattr(self, "format") and self.format == "yyyy-MM-dd":
data = data.date()
if isinstance(data, datetime):
if self._default_timezone and data.tzinfo is None:
data = data.replace(tzinfo=self._default_timezone)
return data
if isinstance(data, date):
return data
if isinstance(data, int):
# Divide by a float to preserve milliseconds on the datetime.
return datetime.utcfromtimestamp(data / 1000.0)
raise ValidationException(f"Could not parse date from the value ({data!r})")