PeriodType implements Serializable { public static List<Period> getPeriodTypePeriods( Period period, org.hisp.dhis.calendar.Calendar calendar ) { List<Period> periods = new ArrayList<>(); PeriodType periodType = period.getPeriodType(); for ( PeriodType type : PeriodType.PERIOD_TYPES ) { if ( periodType.getFrequencyOrder() < type.getFrequencyOrder() || periodType.equals( type ) ) { periods.add( IdentifiableObjectUtils.getPeriodByPeriodType( period, type, calendar ) ); } else { periods.add( null ); } } return periods; }  static void invalidatePeriodCache(); static void setCalendarService( CalendarService calendarService ); static CalendarService getCalendarService(); static org.hisp.dhis.calendar.Calendar getCalendar(); static List<PeriodType> getAvailablePeriodTypes(); static PeriodType getPeriodTypeByName( String name ); static PeriodType getByNameIgnoreCase( String name ); static PeriodType getByIndex( int index ); static List<Period> getPeriodTypePeriods( Period period, org.hisp.dhis.calendar.Calendar calendar ); void setId( int id ); int getId(); abstract String getName(); Period createPeriod(); Period createPeriod( final Date date ); Period createPeriod( Calendar cal ); Period createPeriod( final Date date, final org.hisp.dhis.calendar.Calendar calendar ); Period toIsoPeriod( DateTimeUnit start, DateTimeUnit end ); Period toIsoPeriod( DateTimeUnit dateTimeUnit ); abstract String getIso8601Duration(); abstract Period createPeriod( DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar ); abstract int getFrequencyOrder(); abstract String getSqlInterval(); abstract Date getRewindedDate( Date date, Integer rewindedPeriods ); static Calendar createCalendarInstance(); static Calendar createCalendarInstance( Date date ); static DateTimeUnit createLocalDateUnitInstance( Date date ); static DateTimeUnit createLocalDateUnitInstance( Date date, org.hisp.dhis.calendar.Calendar calendar ); static void clearTimeOfDay( Calendar calendar ); static PeriodType getPeriodTypeFromIsoString( String isoPeriod ); static Period getPeriodFromIsoString( String isoPeriod ); static List<Period> getPeriodsFromIsoStrings( List<String> isoPeriods ); int getPeriodSpan( PeriodType type ); Period createPeriod( DateInterval dateInterval ); String getIsoDate( Period period ); String getIsoDate( DateTimeUnit dateTimeUnit ); abstract String getIsoDate( DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar ); Period createPeriod( String isoDate ); abstract String getIsoFormat(); final Period getNextPeriod( Period period ); Period getNextPeriod( Period period, int periods ); Period getNextPeriod( Period period, org.hisp.dhis.calendar.Calendar calendar ); final Period getPreviousPeriod( Period period ); Period getPreviousPeriod( Period period, int periods ); Period getPreviousPeriod( Period period, org.hisp.dhis.calendar.Calendar calendar ); Period getPreviousYearsPeriod( Period period, int yearCount ); Date getDateWithOffset( Date date, int offset ); boolean spansMultipleCalendarYears(); boolean equalsName( String periodTypeName ); @Override int hashCode(); @Override boolean equals( Object o ); @Override String toString(); static final List<PeriodType> PERIOD_TYPES; static final Map<String, DayOfWeek> MAP_WEEK_TYPE; }
@Test public void testGetPeriodTypePeriods() { Calendar calendar = PeriodType.getCalendar(); Period jan2018 = PeriodType.getPeriodFromIsoString( "201801" ); Period q12018 = PeriodType.getPeriodFromIsoString( "2018Q1" ); Period y2018 = PeriodType.getPeriodFromIsoString( "2018" ); Period fyApril2018 = PeriodType.getPeriodFromIsoString( "2018April" ); int inxMonthly = PeriodType.PERIOD_TYPES.indexOf( new MonthlyPeriodType() ); int inxQuarterly = PeriodType.PERIOD_TYPES.indexOf( new QuarterlyPeriodType() ); int inxYearly = PeriodType.PERIOD_TYPES.indexOf( new YearlyPeriodType() ); int inxFinancialApril = PeriodType.PERIOD_TYPES.indexOf( new FinancialAprilPeriodType() ); List<Period> periods = PeriodType.getPeriodTypePeriods( jan2018, calendar ); assertEquals( jan2018, periods.get( inxMonthly ) ); assertEquals( q12018, periods.get( inxQuarterly ) ); assertEquals( y2018, periods.get( inxYearly ) ); periods = PeriodType.getPeriodTypePeriods( y2018, calendar ); assertNull( periods.get( inxMonthly ) ); assertNull( periods.get( inxQuarterly ) ); assertEquals( y2018, periods.get( inxYearly ) ); assertNull( periods.get( inxFinancialApril ) ); periods = PeriodType.getPeriodTypePeriods( fyApril2018, calendar ); assertNull( periods.get( inxMonthly ) ); assertNull( periods.get( inxQuarterly ) ); assertNull( periods.get( inxYearly ) ); assertEquals( fyApril2018, periods.get( inxFinancialApril ) ); }