public Duration getDuration ( Date startDate , Date endDate ) { Calendar cal = DateHelper . popCalendar ( startDate ) ; int days = getDaysInRange ( startDate , endDate ) ; int duration = 0 ; Day day = Day . getInstance ( cal . get ( Calendar . DAY_OF_WEEK ) ) ; while ( days > 0 ) { if ( isWorkingDate ( cal . getTime ( ) , day ) == true ) { ++ duration ; } -- days ; day = day . getNextDay ( ) ; cal . set ( Calendar . DAY_OF_YEAR , cal . get ( Calendar . DAY_OF_YEAR ) + 1 ) ; } DateHelper . pushCalendar ( cal ) ; return ( Duration . getInstance ( duration , TimeUnit . DAYS ) ) ; }
This method is provided to allow an absolute period of time represented by start and end dates into a duration in working days based on this calendar instance . This method takes account of any exceptions defined for this calendar .