question: private Integer zGetWeekNumberForASevenDayRange ( LocalDate firstDateInRange , WeekFields weekFieldRules , boolean requireUnanimousWeekNumber ) { ArrayList < Integer > weekNumbersList = new ArrayList < Integer > ( ) ; for ( int daysIntoTheFuture = 0 ; daysIntoTheFuture <= 6 ; ++ daysIntoTheFuture ) { LocalDate currentDateInRange ; try { currentDateInRange = firstDateInRange . plusDays ( daysIntoTheFuture ) ; int currentWeekNumber = currentDateInRange . get ( weekFieldRules . weekOfWeekBasedYear ( ) ) ; weekNumbersList . add ( currentWeekNumber ) ; } catch ( Exception ex ) { return 1 ; } } boolean isUnanimous = ( InternalUtilities . areObjectsEqual ( weekNumbersList . get ( 0 ) , weekNumbersList . get ( 6 ) ) ) ; if ( isUnanimous ) { return weekNumbersList . get ( 0 ) ; } if ( requireUnanimousWeekNumber ) { return null ; } int mostCommonWeekNumber = InternalUtilities . getMostCommonElementInList ( weekNumbersList ) ; return mostCommonWeekNumber ; }
target:  zGetWeekNumberForASevenDayRange, This returns a week number for the specified seven day range, according to the supplied weekFieldRules. If all seven days fall on the same week number, then that week number will be returned. If "requireUnanimousWeekNumber" is true and the supplied range falls across two week numbers, then null is returned. If "requireUnanimousWeekNumber" is false and the supplied range falls across two week numbers, then the "majority rules" system is used for determining the returned week number. The majority rules system means that the most common week number in the seven day range will be returned. For example: If days 1 and 2 are in week 30, and days 3 through 7 are in week 31, then the week number 31 will be returned. There is no possibility of a "tie" week number, because the number of days in the range is seven (an odd number). Additionally, the returned week number will always be the correct week number for a minimum of four days out of the seven day range. To make sure that all seven days in the range -can- fall on the same week number, the caller of the function would need to supply a seven day range that starts on the same "first day of the week" that is used by the supplied weekFieldRules. I don't know if there are any special cases where these matching parameters are supplied, but the result is still not a unanimous week number. The week fields object can be created from a specific locale, (including Locale.ISO if desired), or the week fields can be configured to match any desired week field rules. Examples of creating week field instances: WeekFields weekFields = WeekFields.of(Locale locale); WeekFields weekFields = WeekFields.of(DayOfWeek firstDayOfWeek, int minimalDaysInFirstWeek);