def clip_datetime(dt, tz=DEFAULT_TZ, is_dst=None):
if isinstance(dt, datetime.datetime):<EOL><INDENT>dt = make_tz_aware(dt, tz=tz, is_dst=is_dst)<EOL>try:<EOL><INDENT>return pd.Timestamp(dt)<EOL><DEDENT>except (ValueError, AttributeError):<EOL><INDENT>pass<EOL><DEDENT>if dt > MAX_DATETIME:<EOL><INDENT>return MAX_TIMESTAMP<EOL><DEDENT>elif dt < MIN_DATETIME:<EOL><INDENT>return MIN_TIMESTAMP<EOL><DEDENT>return NAT<EOL><DEDENT>return dt<EOL>
Limit a datetime to a valid range for datetime, datetime64, and Timestamp objects
    >>> from datetime import timedelta
    >>> clip_datetime(MAX_DATETIME + timedelta(100)) == pd.Timestamp(MAX_DATETIME, tz='utc') == MAX_TIMESTAMP
    True
    >>> MAX_TIMESTAMP
    Timestamp('2262-04-11 23:47:16.854775+0000', tz='UTC')