code: public static List<Range<Date>> getDateRanges(Date from, Date to, final Period periodGranulation)
        throws InvalidRangeException {
  
      if (from.after(to)) {
        throw buildInvalidRangeException(from, to);
      }
      if (periodGranulation == Period.SINGLE) {
        @SuppressWarnings("unchecked") ArrayList<Range<Date>> list =
            newArrayList(Range.getInstance(from, to));
        return list;
      }
      to = formatToStartOfDay(to);
      from = formatToStartOfDay(from);
      List<Range<Date>> dateRanges = Lists.newArrayList();
      Calendar calendar = buildCalendar(from);
      Date currentProcessDate = calendar.getTime();
      for (Date processEndDate = getDatePeriod(to, periodGranulation).getUpperBound(); !processEndDate
          .before(currentProcessDate); currentProcessDate = calendar.getTime()) {
        Date dateInRange = calendar.getTime();
        Range<Date> dateRange = getDatePeriod(dateInRange, periodGranulation);
        dateRanges.add(dateRange);
        calendar.add(periodGranulation.value, 1);
      }
      calendarCache.add(calendar);
      Range<Date> firstRange = dateRanges.get(0);
      if (firstRange.getLowerBound().before(from)) {
        dateRanges.set(0, Range.getInstance(from, firstRange.getUpperBound()));
      }
      int indexOfLastDateRange = dateRanges.size() - 1;
      Range<Date> lastRange = dateRanges.get(indexOfLastDateRange);
      if (lastRange.getUpperBound().after(to)) {
        dateRanges.set(indexOfLastDateRange, Range.getInstance(lastRange.getLowerBound(), to));
      }
      return dateRanges;
    }
docs: Returns Range&lt;Date&gt; list between given date from and date to by
  period granulation.
  
  @param from the range from.
  @param to the range to.
  @param periodGranulation the range granulation.
  @return Range&lt;Date&gt; list between given date from and date to by
  period granulation.