/** * Returns an ISO8601 formatted string version of the period. * * @return the period string */ public String getIsoDate() { return isoPeriod != null ? isoPeriod : periodType.getIsoDate( this ); }
/** * Returns an iso8601 formatted string representation of the dataUnit * * @param dateTimeUnit Period * @return the period as string */ public String getIsoDate( DateTimeUnit dateTimeUnit ) { return getIsoDate( dateTimeUnit, 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() ) ); }
/** * Returns a list of calendar specific period identifiers for the given collection of * periods and calendar. * * @param periods the list of periods. * @param calendar the calendar to use for generation of iso periods. * @return a list of iso period identifiers. */ public static <T extends IdentifiableObject> List<String> getLocalPeriodIdentifiers( Collection<T> periods, Calendar calendar ) { List<String> localIdentifiers = new ArrayList<>(); for ( IdentifiableObject object : periods ) { Period period = (Period) object; DateTimeUnit dateTimeUnit = calendar.fromIso( period.getStartDate() ); localIdentifiers.add( period.getPeriodType().getIsoDate( dateTimeUnit ) ); } return localIdentifiers; }
protected Period toIsoPeriod( DateTimeUnit start, DateTimeUnit end, org.hisp.dhis.calendar.Calendar calendar ) { DateTimeUnit from = calendar.toIso( start ); DateTimeUnit to = calendar.toIso( end ); return new Period( this, from.toJdkDate(), to.toJdkDate(), getIsoDate( start, calendar ) ); }
/** * Returns a local period identifier for a specific period / calendar. * * @param period the list of periods. * @param calendar the calendar to use for generation of iso periods. * @return Period identifier based on given calendar */ public static String getLocalPeriodIdentifier( Period period, Calendar calendar ) { if ( calendar.isIso8601() ) { return period.getIsoDate(); } return period.getPeriodType().getIsoDate( calendar.fromIso( period.getStartDate() ) ); }
DateTimeUnit dateTimeUnit = calendar.fromIso( period.getStartDate() ); map.put( period.getPeriodType().getIsoDate( dateTimeUnit ), period.getDisplayName() );
/** * @param dateInterval DateInterval to create period from * @return the period. */ public Period createPeriod( DateInterval dateInterval ) { if ( dateInterval == null || dateInterval.getFrom() == null || dateInterval.getTo() == null ) { return null; } org.hisp.dhis.calendar.Calendar cal = getCalendar(); final DateTimeUnit from = cal.toIso( dateInterval.getFrom() ); final DateTimeUnit to = cal.toIso( dateInterval.getTo() ); return new Period( this, from.toJdkDate(), to.toJdkDate(), getIsoDate( from ) ); }
String isoDate = period.getPeriodType().getIsoDate( dateTimeUnit ); map.put( isoDate, new MetadataItem( period.getDisplayName(), includeMetadataDetails ? period : null ) );