def AdjustDateForYearBoundary(to_adjust, latest_date):
    """Handles end-of-year boundaries for dates that are parsed from strings
    that don't include the year. latest_date is the latest date known from
    processing an input. If to_adjust is after latest_date, to_adjust is
    moved back a year.

    For example, an input may have dates 12/31 and 01/01. This crosses the
    year boundary so 01/01 is year X and 12/31 is year X-1.
    """
    if to_adjust <= latest_date:
        return to_adjust
    return to_adjust.replace(year=to_adjust.year-1)