earliest, latestdate algorithm new, first attempt for angular ui datepicker (commented)