public Date getBoundaryDate( Date reportingStartDate, Date reportingEndDate ) { Date returnDate = null; if ( analyticsPeriodBoundaryType.isEndBoundary() ) { DateTime reportingEndDateTime = new DateTime(reportingEndDate); returnDate = reportingEndDateTime.plusDays(1).toDate(); } else { returnDate = new Date( reportingStartDate.getTime() ); } if ( offsetPeriods != null && offsetPeriodType != null ) { returnDate = this.offsetPeriodType.getDateWithOffset( returnDate, getOffsetPeriodsInt() ); } return returnDate; }
/** * Returns a Period which is the previous 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 previous Period on. * @return a Period which is the previous of the given Period. */ public Period getPreviousPeriod( Period period, org.hisp.dhis.calendar.Calendar calendar ) { DateTimeUnit dateWithOffset = getDateWithOffset( createLocalDateUnitInstance( period.getStartDate(), calendar ), -1, calendar ); return createPeriod( dateWithOffset, calendar ); }
/** * Offsets the input date with the provided number of periods within the current period type. * If the offset number is positive, the date is offset into later periods. When the offset is * negative, the date is offset into earlier periods. * @param date for where to start the offset. * @param period how many periods to go back(if negative) or forward(if positive). A value of 0 will * result in the original date to be returned. * @return a new date object that has been offset from the original date passed into the function. */ public Date getDateWithOffset( Date date, int offset ) { org.hisp.dhis.calendar.Calendar calendar = getCalendar(); DateTimeUnit dateTimeUnit = createLocalDateUnitInstance( date, calendar ); return getDateWithOffset( dateTimeUnit, offset, calendar ).toJdkDate(); }
/** * 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. * @param calendar the Calendar to use. * @return a Period which is the next of the given Period. */ public Period getNextPeriod( Period period, org.hisp.dhis.calendar.Calendar calendar ) { DateTimeUnit dateWithOffset = getDateWithOffset( createLocalDateUnitInstance( period.getStartDate(), calendar ), 1, calendar ); return createPeriod( dateWithOffset, calendar ); }