@Test public void testFromMinMax_1m_5d() throws Exception { List<DateRange> dateRanges = DateRangeCalculator.fromMinMax( date("2002-01-01"), date("2002-04-30"), "1m", "5d"); assertEquals(4, dateRanges.size()); assertEquals("[2002-01-01:2002-01-05]", dateRanges.get(0).toString()); assertEquals("[2002-02-01:2002-02-05]", dateRanges.get(1).toString()); assertEquals("[2002-03-01:2002-03-05]", dateRanges.get(2).toString()); assertEquals("[2002-04-01:2002-04-05]", dateRanges.get(3).toString()); }
public static List<DateRange> fromMinMax(Date minDate, Date maxDate, String steppingPeriodLength, String compositingPeriodLength) { List<DateRange> dateRangeList = new ArrayList<>(); Period steppingPeriod = parsePeriod(steppingPeriodLength); Period compositingPeriod = parsePeriod(compositingPeriodLength); final GregorianCalendar calendar = DateUtils.createCalendar(); calendar.setTime(maxDate); calendar.add(Calendar.DAY_OF_MONTH, 1); final Date end = calendar.getTime(); calendar.setTime(minDate); while (true) { final Date periodStart = calendar.getTime(); compositingPeriod.next(calendar); calendar.add(Calendar.SECOND, -1); final Date periodEnd = calendar.getTime(); if (periodEnd.after(end)) { break; } dateRangeList.add(new DateRange(periodStart, periodEnd)); calendar.setTime(periodStart); steppingPeriod.next(calendar); } return dateRangeList; }
DateRangeCalculator { public static List<DateRange> fromMinMax(Date minDate, Date maxDate, String steppingPeriodLength, String compositingPeriodLength) { List<DateRange> dateRangeList = new ArrayList<>(); Period steppingPeriod = parsePeriod(steppingPeriodLength); Period compositingPeriod = parsePeriod(compositingPeriodLength); final GregorianCalendar calendar = DateUtils.createCalendar(); calendar.setTime(maxDate); calendar.add(Calendar.DAY_OF_MONTH, 1); final Date end = calendar.getTime(); calendar.setTime(minDate); while (true) { final Date periodStart = calendar.getTime(); compositingPeriod.next(calendar); calendar.add(Calendar.SECOND, -1); final Date periodEnd = calendar.getTime(); if (periodEnd.after(end)) { break; } dateRangeList.add(new DateRange(periodStart, periodEnd)); calendar.setTime(periodStart); steppingPeriod.next(calendar); } return dateRangeList; } }
DateRangeCalculator { public static List<DateRange> fromMinMax(Date minDate, Date maxDate, String steppingPeriodLength, String compositingPeriodLength) { List<DateRange> dateRangeList = new ArrayList<>(); Period steppingPeriod = parsePeriod(steppingPeriodLength); Period compositingPeriod = parsePeriod(compositingPeriodLength); final GregorianCalendar calendar = DateUtils.createCalendar(); calendar.setTime(maxDate); calendar.add(Calendar.DAY_OF_MONTH, 1); final Date end = calendar.getTime(); calendar.setTime(minDate); while (true) { final Date periodStart = calendar.getTime(); compositingPeriod.next(calendar); calendar.add(Calendar.SECOND, -1); final Date periodEnd = calendar.getTime(); if (periodEnd.after(end)) { break; } dateRangeList.add(new DateRange(periodStart, periodEnd)); calendar.setTime(periodStart); steppingPeriod.next(calendar); } return dateRangeList; }  }
DateRangeCalculator { public static List<DateRange> fromMinMax(Date minDate, Date maxDate, String steppingPeriodLength, String compositingPeriodLength) { List<DateRange> dateRangeList = new ArrayList<>(); Period steppingPeriod = parsePeriod(steppingPeriodLength); Period compositingPeriod = parsePeriod(compositingPeriodLength); final GregorianCalendar calendar = DateUtils.createCalendar(); calendar.setTime(maxDate); calendar.add(Calendar.DAY_OF_MONTH, 1); final Date end = calendar.getTime(); calendar.setTime(minDate); while (true) { final Date periodStart = calendar.getTime(); compositingPeriod.next(calendar); calendar.add(Calendar.SECOND, -1); final Date periodEnd = calendar.getTime(); if (periodEnd.after(end)) { break; } dateRangeList.add(new DateRange(periodStart, periodEnd)); calendar.setTime(periodStart); steppingPeriod.next(calendar); } return dateRangeList; }  static List<DateRange> fromDateList(Date... dateList); static List<DateRange> fromMinMax(Date minDate, Date maxDate, String steppingPeriodLength, String compositingPeriodLength); }
DateRangeCalculator { public static List<DateRange> fromMinMax(Date minDate, Date maxDate, String steppingPeriodLength, String compositingPeriodLength) { List<DateRange> dateRangeList = new ArrayList<>(); Period steppingPeriod = parsePeriod(steppingPeriodLength); Period compositingPeriod = parsePeriod(compositingPeriodLength); final GregorianCalendar calendar = DateUtils.createCalendar(); calendar.setTime(maxDate); calendar.add(Calendar.DAY_OF_MONTH, 1); final Date end = calendar.getTime(); calendar.setTime(minDate); while (true) { final Date periodStart = calendar.getTime(); compositingPeriod.next(calendar); calendar.add(Calendar.SECOND, -1); final Date periodEnd = calendar.getTime(); if (periodEnd.after(end)) { break; } dateRangeList.add(new DateRange(periodStart, periodEnd)); calendar.setTime(periodStart); steppingPeriod.next(calendar); } return dateRangeList; }  static List<DateRange> fromDateList(Date... dateList); static List<DateRange> fromMinMax(Date minDate, Date maxDate, String steppingPeriodLength, String compositingPeriodLength);  }