BiMonthlyPeriodType extends CalendarPeriodType { @Override public List<Period> generateRollingPeriods( DateTimeUnit dateTimeUnit, Calendar calendar ) { dateTimeUnit.setDay( 1 ); DateTimeUnit iterationDateTimeUnit = calendar.minusMonths( dateTimeUnit, (dateTimeUnit.getMonth() % 2) + 10 ); List<Period> periods = Lists.newArrayList(); for ( int i = 0; i < 6; i++ ) { periods.add( createPeriod( iterationDateTimeUnit, calendar ) ); iterationDateTimeUnit = calendar.plusMonths( iterationDateTimeUnit, 2 ); } return periods; }  @Override String getName(); @Override Period createPeriod( DateTimeUnit dateTimeUnit, Calendar calendar ); @Override int getFrequencyOrder(); @Override String getSqlInterval(); @Override DateTimeUnit getDateWithOffset(  DateTimeUnit dateTimeUnit, int offset, Calendar calendar ); @Override List<Period> generatePeriods( DateTimeUnit dateTimeUnit ); @Override List<Period> generateRollingPeriods( DateTimeUnit dateTimeUnit, Calendar calendar ); @Override String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar ); @Override String getIsoFormat(); @Override Date getRewindedDate( Date date, Integer rewindedPeriods ); @Override String getIso8601Duration(); static final String NAME; static final int FREQUENCY_ORDER; static final String SQL_INTERVAL; }
@Test public void testGenerateRollingPeriods() { testDate = new DateTime( 2009, 8, 15, 0, 0 ); List<Period> periods = periodType.generateRollingPeriods( testDate.toDate() ); assertEquals( 6, periods.size() ); assertEquals( periodType.createPeriod( new DateTime( 2008, 9, 1, 0, 0 ).toDate() ), periods.get( 0 ) ); assertEquals( periodType.createPeriod( new DateTime( 2008, 11, 1, 0, 0 ).toDate() ), periods.get( 1 ) ); assertEquals( periodType.createPeriod( new DateTime( 2009, 1, 1, 0, 0 ).toDate() ), periods.get( 2 ) ); assertEquals( periodType.createPeriod( new DateTime( 2009, 3, 1, 0, 0 ).toDate() ), periods.get( 3 ) ); assertEquals( periodType.createPeriod( new DateTime( 2009, 5, 1, 0, 0 ).toDate() ), periods.get( 4 ) ); assertEquals( periodType.createPeriod( new DateTime( 2009, 7, 1, 0, 0 ).toDate() ), periods.get( 5 ) ); }