code: private static int getInterval(long diffInMilliSecs, long hourInterval, int maxIntervals) {
  
      long totalHours = DoubleMath.roundToInt((double) diffInMilliSecs / (60 * 60 * 1000), RoundingMode.CEILING);
      long totalIntervals = DoubleMath.roundToInt((double) totalHours / hourInterval, RoundingMode.CEILING);
      if (totalIntervals > maxIntervals) {
        hourInterval = DoubleMath.roundToInt((double) totalHours / maxIntervals, RoundingMode.CEILING);
      }
      return Ints.checkedCast(hourInterval);
    }
docs: recalculate interval(in hours) if total number of partitions greater than maximum number of allowed partitions
  
  @param diffInMilliSecs difference in range
  @param hourInterval hour interval (ex: 4 hours)
  @param maxIntervals max number of allowed partitions
  @return calculated interval in hours