private Integer zGetWeekNumberForASevenDayRange ( LocalDate firstDateInRange , WeekFields weekFieldRules , boolean requireUnanimousWeekNumber ) { // Get the week number for each of the seven days in the range. ArrayList < Integer > weekNumbersList = new ArrayList < Integer > ( ) ; for ( int daysIntoTheFuture = 0 ; daysIntoTheFuture <= 6 ; ++ daysIntoTheFuture ) { LocalDate currentDateInRange ; // This try block handles an exception that can occur at LocalDate.MAX try { currentDateInRange = firstDateInRange . plusDays ( daysIntoTheFuture ) ; int currentWeekNumber = currentDateInRange . get ( weekFieldRules . weekOfWeekBasedYear ( ) ) ; weekNumbersList . add ( currentWeekNumber ) ; } catch ( Exception ex ) { return 1 ; } } // Find out if all the week numbers are the same. // We can check for a unanimous sequence by looking at the first and last number. boolean isUnanimous = ( InternalUtilities . areObjectsEqual ( weekNumbersList . get ( 0 ) , weekNumbersList . get ( 6 ) ) ) ; // If the week numbers are unanimous, then return the unanimous week number. if ( isUnanimous ) { return weekNumbersList . get ( 0 ) ; } // The week number is not unanimous. // If unanimous week numbers are required, then return null. if ( requireUnanimousWeekNumber ) { return null ; } // Otherwise, return the most common week number. int mostCommonWeekNumber = InternalUtilities . getMostCommonElementInList ( weekNumbersList ) ; return mostCommonWeekNumber ; }
zGetWeekNumberForASevenDayRange This returns a week number for the specified seven day range according to the supplied weekFieldRules .