getEndDate function working correctly