/** * Returns an instance of a DateUnit. * * @param date date of calendar in local calendar * @return an instance of a Calendar without any time of day. */ public static DateTimeUnit createLocalDateUnitInstance( Date date ) { return createLocalDateUnitInstance( date, getCalendar() ); }
/** * Returns an iso8601 formatted string representation of the period * * @param period Period * @return the period as string */ public String getIsoDate( Period period ) { return getIsoDate( createLocalDateUnitInstance( period.getStartDate() ) ); }
/** * 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 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 ); }
/** * 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 ); }