def convert_to_datetime(input):
 if isinstance(input, datetime):
  return input
 elif isinstance(input, date):
  return datetime.fromordinal(input.toordinal())
 elif isinstance(input, str):
  m = _DATE_REGEX.match(input)
  if (not m):
   raise ValueError('Invalid date string')
  values = [(k, int((v or 0))) for (k, v) in m.groupdict().items()]
  values = dict(values)
  return datetime(**values)
 raise TypeError(('Unsupported input type: %s' % type(input)))

def convert_to_datetime ( input ) : if isinstance ( input , datetime ) : return input elif isinstance ( input , date ) : return datetime . fromordinal ( input . toordinal ( ) ) elif isinstance ( input , str ) : m = _DATE_REGEX . match ( input ) if ( not m ) : raise ValueError ( 'Invalid date string' ) values = [ ( k , int ( ( v or 0 ) ) ) for ( k , v ) in m . groupdict ( ) . items ( ) ] values = dict ( values ) return datetime ( ** values ) raise TypeError ( ( 'Unsupported input type: %s' % type ( input ) ) )
converts the given object to a datetime object .