PeriodType implements Serializable { public static PeriodType getPeriodTypeFromIsoString( String isoPeriod ) { DateUnitType dateUnitType = DateUnitType.find( isoPeriod ); return dateUnitType != null ? PERIOD_TYPE_MAP.get( dateUnitType.getName() ) : null; }  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 testGetPeriodTypeFromIsoString() { assertEquals( PeriodType.getPeriodTypeFromIsoString( "2011" ).getName(), "Yearly" ); assertEquals( PeriodType.getPeriodTypeFromIsoString( "201101" ).getName(), "Monthly" ); assertEquals( PeriodType.getPeriodTypeFromIsoString( "2011W1" ).getName(), "Weekly" ); assertEquals( PeriodType.getPeriodTypeFromIsoString( "2011W32" ).getName(), "Weekly" ); assertEquals( PeriodType.getPeriodTypeFromIsoString( "20110101" ).getName(), "Daily" ); assertEquals( PeriodType.getPeriodTypeFromIsoString( "2011Q3" ).getName(), "Quarterly" ); assertEquals( PeriodType.getPeriodTypeFromIsoString( "201101B" ).getName(), "BiMonthly" ); assertEquals( PeriodType.getPeriodTypeFromIsoString( "2011S1" ).getName(), "SixMonthly" ); assertEquals( PeriodType.getPeriodTypeFromIsoString( "2011AprilS1" ).getName(), "SixMonthlyApril" ); assertEquals( PeriodType.getPeriodTypeFromIsoString( "2011April" ).getName(), "FinancialApril" ); assertEquals( PeriodType.getPeriodTypeFromIsoString( "2011July" ).getName(), "FinancialJuly" ); assertEquals( PeriodType.getPeriodTypeFromIsoString( "2011Oct" ).getName(), "FinancialOct" ); assertNull( PeriodType.getPeriodTypeFromIsoString( "201" ) ); assertNull( PeriodType.getPeriodTypeFromIsoString( "20111" ) ); assertNull( PeriodType.getPeriodTypeFromIsoString( "201W2" ) ); assertNull( PeriodType.getPeriodTypeFromIsoString( "2011Q12" ) ); assertNull( PeriodType.getPeriodTypeFromIsoString( "2011W234" ) ); assertNull( PeriodType.getPeriodTypeFromIsoString( "201er2345566" ) ); assertNull( PeriodType.getPeriodTypeFromIsoString( "2011Q10" ) ); }