code: public static Range<Date> getDatePeriod(final Date date, final Period period) {
  
      Calendar calendar = buildCalendar(date);
      Range<Date> dateRange = null;
      Date startDate = calendar.getTime();
      Date endDate = calendar.getTime();
      if (period != Period.DAY) {
        for (; period.getValue(date) == period.getValue(calendar.getTime()); calendar
            .add(DAY_OF_MONTH, 1)) {
          endDate = calendar.getTime();
        }
  
        calendar.setTime(date);
        for (; period.getValue(date) == period.getValue(calendar.getTime()); calendar
            .add(DAY_OF_MONTH, -1)) {
          startDate = calendar.getTime();
        }
      }
      calendarCache.add(calendar);
      dateRange = Range.getInstance(startDate, endDate);
      return dateRange;
    }
docs: Return Range&lt;Date&gt; by given date and period.
  
  @param date the date belong to the range.
  @param period the range granulation.
  @return a Range&lt;Date&gt; by given date and period.