YearlyPeriodType extends CalendarPeriodType { @Override public Period createPeriod( DateTimeUnit dateTimeUnit, Calendar calendar ) { DateTimeUnit start = new DateTimeUnit( dateTimeUnit ); DateTimeUnit end = new DateTimeUnit( dateTimeUnit ); start.setDay( 1 ); start.setMonth( 1 ); end.setMonth( calendar.monthsInYear() ); 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 List<Period> generateLast5Years( Date date ); @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, 1, 1, 0, 0 ); endDate = new DateTime( 2009, 12, 31, 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 ); 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( 2010, 1, 1, 0, 0 ); endDate = new DateTime( 2010, 12, 31, 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( 2008, 1, 1, 0, 0 ); endDate = new DateTime( 2008, 12, 31, 0, 0 ); assertEquals( startDate.toDate(), period.getStartDate() ); assertEquals( endDate.toDate(), period.getEndDate() ); }