QuarterlyPeriodType extends CalendarPeriodType { @Override public Period createPeriod( DateTimeUnit dateTimeUnit, Calendar calendar ) { DateTimeUnit start = new DateTimeUnit( dateTimeUnit ); start.setMonth( ((dateTimeUnit.getMonth() - 1) - ((dateTimeUnit.getMonth() - 1) % 3)) + 1 ); start.setDay( 1 ); if ( start.getMonth() > 12 ) { start.setYear( start.getYear() + 1 ); start.setMonth( 1 ); } DateTimeUnit end = new DateTimeUnit( start ); end = calendar.plusMonths( end, 2 ); end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) ); return toIsoPeriod( start, end, calendar ); }  @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( Date date ); @Override List<Period> generateRollingPeriods( DateTimeUnit dateTimeUnit, Calendar calendar ); @Override String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar ); @Override String getIsoFormat(); @Override String getIso8601Duration(); @Override Date getRewindedDate( Date date, Integer rewindedPeriods ); static final String NAME; static final int FREQUENCY_ORDER; static final String SQL_INTERVAL; }
@Test public void testCreatePeriod() { testDate = new DateTime( 2009, 8, 15, 0, 0 ); startDate = new DateTime( 2009, 7, 1, 0, 0 ); endDate = new DateTime( 2009, 9, 30, 0, 0 ); Period period = periodType.createPeriod( testDate.toDate() ); assertEquals( startDate.toDate(), period.getStartDate() ); assertEquals( endDate.toDate(), period.getEndDate() ); testDate = new DateTime( 2009, 4, 15, 0, 0 ); startDate = new DateTime( 2009, 4, 1, 0, 0 ); endDate = new DateTime( 2009, 6, 30, 0, 0 ); period = periodType.createPeriod( testDate.toDate() ); assertEquals( startDate.toDate(), period.getStartDate() ); assertEquals( endDate.toDate(), period.getEndDate() ); testDate = new DateTime( 2014, 11, 20, 0, 0 ); startDate = new DateTime( 2014, 10, 1, 0, 0 ); endDate = new DateTime( 2014, 12, 31, 0, 0 ); period = periodType.createPeriod( testDate.toDate() ); assertEquals( startDate.toDate(), period.getStartDate() ); assertEquals( endDate.toDate(), period.getEndDate() ); }
@Test public void testGetNextPeriod() { testDate = new DateTime( 2009, 8, 15, 0, 0 ); Period period = periodType.createPeriod( testDate.toDate() ); period = periodType.getNextPeriod( period ); startDate = new DateTime( 2009, 10, 1, 0, 0 ); endDate = new DateTime( 2009, 12, 31, 0, 0 ); assertEquals( startDate.toDate(), period.getStartDate() ); assertEquals( endDate.toDate(), period.getEndDate() ); }
@Test public void testGetNextPeriods() { testDate = new DateTime( 2009, 8, 15, 0, 0 ); Period period = periodType.createPeriod( testDate.toDate() ); period = periodType.getNextPeriod( period, 3 ); startDate = new DateTime( 2010, 4, 1, 0, 0 ); endDate = new DateTime( 2010, 6, 30, 0, 0 ); assertEquals( startDate.toDate(), period.getStartDate() ); assertEquals( endDate.toDate(), period.getEndDate() ); }
@Test public void testGetPreviousPeriod() { testDate = new DateTime( 2009, 8, 15, 0, 0 ); Period period = periodType.createPeriod( testDate.toDate() ); period = periodType.getPreviousPeriod( period ); startDate = new DateTime( 2009, 4, 1, 0, 0 ); endDate = new DateTime( 2009, 6, 30, 0, 0 ); assertEquals( startDate.toDate(), period.getStartDate() ); assertEquals( endDate.toDate(), period.getEndDate() ); }
@Test public void testGenerateLast5Years() { testDate = new DateTime( 2009, 8, 15, 0, 0 ); List<Period> periods = periodType.generateLast5Years( testDate.toDate() ); assertEquals( 20, periods.size() ); assertEquals( periodType.createPeriod( new DateTime( 2005, 1, 1, 0, 0 ).toDate() ), periods.get( 0 ) ); assertEquals( periodType.createPeriod( new DateTime( 2005, 4, 1, 0, 0 ).toDate() ), periods.get( 1 ) ); assertEquals( periodType.createPeriod( new DateTime( 2005, 7, 1, 0, 0 ).toDate() ), periods.get( 2 ) ); assertEquals( periodType.createPeriod( new DateTime( 2005, 10, 1, 0, 0 ).toDate() ), periods.get( 3 ) ); }
@Test public void testGetPeriodsBetween() { assertEquals( 1, periodType.createPeriod().getPeriodSpan( periodType ) ); assertEquals( 2, new SixMonthlyPeriodType().createPeriod().getPeriodSpan( periodType ) ); assertEquals( 4, new YearlyPeriodType().createPeriod().getPeriodSpan( periodType ) ); }