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;
}

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 ; }
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 ) ;
