code: private static int getInterval(long diffInMilliSecs, long hourInterval, int maxIntervals) {
      long dayInterval = TimeUnit.HOURS.toDays(hourInterval);
      int totalHours = DoubleMath.roundToInt((double) diffInMilliSecs / (60 * 60 * 1000), RoundingMode.CEILING);
      int totalIntervals = DoubleMath.roundToInt((double) totalHours / (dayInterval * 24), RoundingMode.CEILING);
      if (totalIntervals > maxIntervals) {
        hourInterval = DoubleMath.roundToInt((double) totalHours / maxIntervals, RoundingMode.CEILING);
        dayInterval = DoubleMath.roundToInt((double) hourInterval / 24, RoundingMode.CEILING);
      }
      return Ints.checkedCast(dayInterval);
    }
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: 24 hours)
  @param maxIntervals max number of allowed partitions
  @return calculated interval in days