@Test public void testFromMinMax_1w_1w_enfOfDec() throws Exception { List<DateRange> dateRanges; dateRanges = DateRangeCalculator.fromMinMax( date("2004-12-22"), date("2005-01-04"), "1w", "1w"); assertEquals("[2004-12-22:2004-12-28]", dateRanges.get(0).toString()); dateRanges = DateRangeCalculator.fromMinMax( date("2004-12-23"), date("2005-01-04"), "1w", "1w"); assertEquals(1, dateRanges.size()); assertEquals("[2004-12-23:2004-12-29]", dateRanges.get(0).toString()); dateRanges = DateRangeCalculator.fromMinMax( date("2004-12-24"), date("2005-01-04"), "1w", "1w"); assertEquals(1, dateRanges.size()); assertEquals("[2004-12-24:2004-12-31]", dateRanges.get(0).toString()); dateRanges = DateRangeCalculator.fromMinMax( date("2004-12-25"), date("2005-01-04"), "1w", "1w"); assertEquals(1, dateRanges.size()); assertEquals("[2004-12-25:2005-01-01]", dateRanges.get(0).toString()); dateRanges = DateRangeCalculator.fromMinMax( date("2004-12-26"), date("2005-01-04"), "1w", "1w"); assertEquals(1, dateRanges.size()); assertEquals("[2004-12-26:2005-01-02]", dateRanges.get(0).toString()); dateRanges = DateRangeCalculator.fromMinMax( date("2003-12-22"), date("2004-01-04"), "1w", "1w"); assertEquals("[2003-12-22:2003-12-28]", dateRanges.get(0).toString()); dateRanges = DateRangeCalculator.fromMinMax( date("2003-12-23"), date("2004-01-04"), "1w", "1w"); assertEquals(1, dateRanges.size()); assertEquals("[2003-12-23:2003-12-29]", dateRanges.get(0).toString()); dateRanges = DateRangeCalculator.fromMinMax( date("2003-12-24"), date("2004-01-04"), "1w", "1w"); assertEquals(1, dateRanges.size()); assertEquals("[2003-12-24:2003-12-31]", dateRanges.get(0).toString()); dateRanges = DateRangeCalculator.fromMinMax( date("2003-12-25"), date("2004-01-04"), "1w", "1w"); assertEquals(1, dateRanges.size()); assertEquals("[2003-12-25:2004-01-01]", dateRanges.get(0).toString()); dateRanges = DateRangeCalculator.fromMinMax( date("2003-12-26"), date("2004-01-04"), "1w", "1w"); assertEquals(1, dateRanges.size()); assertEquals("[2003-12-26:2004-01-02]", dateRanges.get(0).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);  }