def _adjust_n_years(other, n, month, reference_day):
    """Adjust the number of times an annual offset is applied based on
    another date, and the reference day provided"""
    if n > 0:
        if (other.month < month or other.month == month and other.day <
            reference_day):
            n -= 1
    elif other.month > month or other.month == month and other.day > reference_day:
        n += 1
    return n
