/** * Returns a Period which is the next of the given Period. Only valid * Periods are returned. If the given Period is of different PeriodType than * the executing PeriodType, or the given Period is invalid, the returned * Period might overlap the given Period. * * @param period the Period to base the next Period on. * @return a Period which is the next of the given Period. */ public final Period getNextPeriod( Period period ) { return getNextPeriod( period, getCalendar() ); }
/** * Returns the next period determined by the given number of periods. * * @param period the Period to base the next Period on. * @param periods the number of periods into the future. * @return the next period. */ public Period getNextPeriod( Period period, int periods ) { Period nextPeriod = period; if ( periods > 0 ) { org.hisp.dhis.calendar.Calendar calendar = getCalendar(); for ( int i = 0; i < periods; i++ ) { nextPeriod = getNextPeriod( nextPeriod, calendar ); } } return nextPeriod; }
/** * Returns all Periods of the specified PeriodType with start date after or * equal the specified start date and end date before or equal the specified * end date. * * The periods returned do not need to be in the database. * * @param periodType the PeriodType. * @param startDate the ultimate start date. * @param endDate the ultimate end date. * @return a list of all Periods with start date after or equal the * specified start date and end date before or equal the specified * end date, or an empty list if no Periods match. */ private Set<Period> getPeriodsBetweenDates( PeriodType periodType, Date startDate, Date endDate ) { Set<Period> periods = new HashSet<Period>(); Period period = periodType.createPeriod( startDate ); if ( !period.getStartDate().before( startDate ) && !period.getEndDate().after( endDate ) ) { periods.add( period ); } period = periodType.getNextPeriod( period ); while ( !period.getEndDate().after( endDate ) ) { periods.add( period ); period = periodType.getNextPeriod( period ); } return periods; }
/** * Returns the latest period which is open for data input. Returns null if * data element is not associated with any data sets. * * @return the latest period which is open for data input. */ public Period getLatestOpenFuturePeriod() { int periods = getOpenFuturePeriods(); PeriodType periodType = getPeriodType(); if ( periodType != null ) { Period period = periodType.createPeriod(); // Rewind one as 0 open periods implies current period is locked period = periodType.getPreviousPeriod( period ); return periodType.getNextPeriod( period, periods ); } return null; }
pNext = periodType.getNextPeriod( pNext );