/** * Given a period, and a date that falls within that period, create a range of dates such * that the period is contained exactly within [startDate <= {range} < endDate] * * @param date a calendar object of a date falling in that range * @param period something in CALENDAR_PERIODS * @return resulting range of dates */ public static DateRange toDateRange(Calendar date, int period) { // defensively copy the calendar so we don't break anything outside. Calendar cal = (Calendar) date.clone(); toStartOfPeriod(cal, period); Date startDate = new Date(cal.getTimeInMillis()); cal.add(period, 1); Date endDate = new Date(cal.getTimeInMillis()); return new DateRange(startDate, endDate); }
/** * Given a period, and a date that falls within that period, create a range of dates such * that the period is contained exactly within [startDate <= {range} < endDate] * * @param date a calendar object of a date falling in that range * @param period something in CALENDAR_PERIODS */ public static DateRange toDateRange(Calendar date, int period) { // defensively copy the calendar so we don't break anything outside. Calendar cal = (Calendar) date.clone(); toStartOfPeriod(cal, period); Date startDate = new Date(cal.getTimeInMillis()); cal.add(period, 1); Date endDate = new Date(cal.getTimeInMillis()); return new DateRange(startDate, endDate); }