def add_years(datetime_like_object, n, return_date=False):
    """
    Returns a time that n years after a time.

    :param datetimestr: a datetime object or a datetime str
    :param n: number of years, value can be negative
    :param return_date: returns a date object instead of datetime

    **中文文档**

    返回给定日期N年之后的时间。
    """
    a_datetime = parser.parse_datetime(datetime_like_object)

    # try assign year, month, day
    try:
        a_datetime = datetime(
            a_datetime.year + n, a_datetime.month, a_datetime.day,
            a_datetime.hour, a_datetime.minute, a_datetime.second,
            a_datetime.microsecond, tzinfo=a_datetime.tzinfo,
        )
    except ValueError:  # Must be xxxx-02-29
        a_datetime = datetime(
            a_datetime.year + n, 2, 28,
            a_datetime.hour, a_datetime.minute,
            a_datetime.second, a_datetime.microsecond)

    if return_date:  # pragma: no cover
        return a_datetime.date()
    else:
        return a_datetime