DateTimePeriod { public List<DateTimePeriod> toFiveMinutes() { ArrayList<DateTimePeriod> list = new ArrayList<DateTimePeriod>(); DateTime currentStart = getStart(); DateTime nextStart = currentStart.plusMinutes(5); while (nextStart.isBefore(getEnd()) || nextStart.isEqual(getEnd())) { list.add(new DateTimeFiveMinutes(currentStart, nextStart)); currentStart = nextStart; nextStart = currentStart.plusMinutes(5); } return list; } protected  DateTimePeriod(DateTime start, DateTime end, DateTimeDuration duration, String keyPattern,
            String longNamePattern, String shortNamePattern, String indexNamePattern); DateTime getStart(); DateTime getEnd(); DateTimeDuration getDuration(); String getKey(); String getLongName(); String getShortName(); String getIndexName(); abstract DateTimePeriod getNext(); abstract DateTimePeriod getPrevious(); abstract DateTimeDuration getDefaultSubDuration(); List<DateTimePeriod> toPeriods(DateTimeDuration duration); List<DateTimePeriod> toFiveMinutes(); List<DateTimePeriod> toHours(); List<DateTimePeriod> toDays(); List<DateTimePeriod> toMonths(); List<DateTimePeriod> toYears(); @Override boolean equals(Object object); @Override int hashCode(); static DateTimePeriod create(DateTimeDuration duration, DateTime start); static DateTimePeriod createYear(int year, DateTimeZone zone); static DateTimePeriod createYear(DateTime start); static DateTimePeriod createMonth(int year, int month, DateTimeZone zone); static DateTimePeriod createMonth(DateTime start); static DateTimePeriod createDay(int year, int month, int day, DateTimeZone zone); static DateTimePeriod createDay(DateTime start); static DateTimePeriod createHour(int year, int month, int day, int hour, DateTimeZone zone); static DateTimePeriod createHour(DateTime start); static DateTimePeriod createFiveMinutes(int year, int month, int day, int hour, int minute, DateTimeZone zone); static DateTimePeriod createFiveMinutes(DateTime start); static List<DateTimePeriod> createLastYearMonths(DateTimeZone zone);  }
@Test public void toFiveMinutes() throws Exception { DateTimePeriod period0 = DateTimePeriod.createFiveMinutes(2009, 1, 1, 0, 0, DateTimeZone.UTC); List<DateTimePeriod> periods = period0.toFiveMinutes(); Assert.assertArrayEquals(new DateTimePeriod[] { DateTimePeriod.createFiveMinutes(2009, 1, 1, 0, 0, DateTimeZone.UTC) }, periods.toArray(new DateTimePeriod[0])); period0 = new DateTimeFiveMinutes(new DateTime(2009,1,1,0,0,0,0,DateTimeZone.UTC), new DateTime(2009,1,1,0,10,0,0,DateTimeZone.UTC)); periods = period0.toPeriods(DateTimeDuration.FIVE_MINUTES); Assert.assertArrayEquals(new DateTimePeriod[] { DateTimePeriod.createFiveMinutes(2009, 1, 1, 0, 0, DateTimeZone.UTC), DateTimePeriod.createFiveMinutes(2009, 1, 1, 1, 5, DateTimeZone.UTC) }, periods.toArray(new DateTimePeriod[0])); period0 = new DateTimeFiveMinutes(new DateTime(2009,1,1,0,0,0,0,DateTimeZone.UTC), new DateTime(2009,1,1,0,4,59,999,DateTimeZone.UTC)); periods = period0.toFiveMinutes(); Assert.assertArrayEquals(new DateTimePeriod[] {}, periods.toArray(new DateTimePeriod[0])); }