Fix end_date algorithm