def normalize_date_aggressively(date):
    """Normalize date, stripping date parts until a valid date is obtained."""
    def _strip_last_part(date):
        parts = date.split('-')
        return '-'.join(parts[:-1])

    fake_dates = {'0000', '9999'}
    if date in fake_dates:
        return None
    try:
        return normalize_date(date)
    except ValueError:
        if '-' not in date:
            raise
        else:
            new_date = _strip_last_part(date)
            return normalize_date_aggressively(new_date)
def normalize_date_aggressively ( date ) : def _strip_last_part ( date ) : parts = date . split ( '-' ) return '-' . join ( parts [ : - 1 ] ) fake_dates = { '0000' , '9999' } if date in fake_dates : return None try : return normalize_date ( date ) except ValueError : if '-' not in date : raise else : new_date = _strip_last_part ( date ) return normalize_date_aggressively ( new_date )
Normalize date, stripping date parts until a valid date is obtained.