def to_python(self, value):
if value in validators.EMPTY_VALUES:<EOL><INDENT>return None<EOL><DEDENT>if isinstance(value, datetime.datetime):<EOL><INDENT>return value<EOL><DEDENT>if isinstance(value, datetime.date):<EOL><INDENT>return datetime.datetime(value.year, value.month, value.day)<EOL><DEDENT>if isinstance(value, list):<EOL><INDENT>if len(value) != <NUM_LIT:4>:<EOL><INDENT>raise ValidationError(self.error_messages['<STR_LIT>'])<EOL><DEDENT>if value[<NUM_LIT:0>] in validators.EMPTY_VALUES and value[<NUM_LIT:1>] invalidators.EMPTY_VALUES and value[<NUM_LIT:2>] invalidators.EMPTY_VALUES and value[<NUM_LIT:3>] invalidators.EMPTY_VALUES:<EOL><INDENT>return None<EOL><DEDENT>start_value = '<STR_LIT>' % tuple(value[:<NUM_LIT:2>])<EOL>end_value = '<STR_LIT>' % tuple(value[<NUM_LIT:2>:])<EOL><DEDENT>start_datetime = None<EOL>end_datetime = None<EOL>for format in self.input_formats or formats.get_format('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>start_datetime = datetime.datetime(*time.strptime(start_value, format)[:<NUM_LIT:6>])<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>for format in self.input_formats or formats.get_format('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>end_datetime = datetime.datetime(*time.strptime(end_value, format)[:<NUM_LIT:6>])<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>return (start_datetime, end_datetime)<EOL>
Validates that the input can be converted to a datetime. Returns a
Python datetime.datetime object.