def es_to_datetime(value):
 if ((not value) or isinstance(value, (date, datetime))):
  return
 if (len(value) == 26):
  try:
   return datetime.strptime(value, '%Y-%m-%dT%H:%M:%S.%f')
  except (TypeError, ValueError):
   pass
 elif (len(value) == 19):
  try:
   return datetime.strptime(value, '%Y-%m-%dT%H:%M:%S')
  except (TypeError, ValueError):
   pass
 elif (len(value) == 10):
  try:
   return datetime.strptime(value, '%Y-%m-%d')
  except (TypeError, ValueError):
   pass
 return value

def es_to_datetime ( value ) : if ( ( not value ) or isinstance ( value , ( date , datetime ) ) ) : return if ( len ( value ) == 26 ) : try : return datetime . strptime ( value , '%Y-%m-%dT%H:%M:%S.%f' ) except ( TypeError , ValueError ) : pass elif ( len ( value ) == 19 ) : try : return datetime . strptime ( value , '%Y-%m-%dT%H:%M:%S' ) except ( TypeError , ValueError ) : pass elif ( len ( value ) == 10 ) : try : return datetime . strptime ( value , '%Y-%m-%d' ) except ( TypeError , ValueError ) : pass return value
returns a datetime given an elasticsearch date/datetime field .