Search in sources :

Example 51 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.

the class QuarterlyPeriodType method getPreviousPeriod.

@Override
public Period getPreviousPeriod(Period period, org.hisp.dhis.calendar.Calendar calendar) {
    DateTimeUnit dateTimeUnit = createLocalDateUnitInstance(period.getStartDate(), calendar);
    dateTimeUnit = calendar.minusMonths(dateTimeUnit, 3);
    return createPeriod(dateTimeUnit, calendar);
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit)

Example 52 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.

the class AnalyticsUtils method getDimensionItemNameMap.

/**
     * Returns a mapping between identifiers and names for the given query.
     *
     * @param params the data query parameters.
     * @return a mapping between identifiers and names.
     */
public static Map<String, String> getDimensionItemNameMap(DataQueryParams params) {
    List<DimensionalObject> dimensions = params.getDimensionsAndFilters();
    Map<String, String> map = new HashMap<>();
    Calendar calendar = PeriodType.getCalendar();
    for (DimensionalObject dimension : dimensions) {
        for (DimensionalItemObject item : dimension.getItems()) {
            if (DimensionType.PERIOD.equals(dimension.getDimensionType()) && !calendar.isIso8601()) {
                Period period = (Period) item;
                DateTimeUnit dateTimeUnit = calendar.fromIso(period.getStartDate());
                map.put(period.getPeriodType().getIsoDate(dateTimeUnit), period.getDisplayName());
            } else {
                map.put(item.getDimensionItem(), item.getDisplayProperty(params.getDisplayProperty()));
            }
            if (DimensionType.ORGANISATION_UNIT.equals(dimension.getDimensionType()) && params.isHierarchyMeta()) {
                OrganisationUnit unit = (OrganisationUnit) item;
                map.putAll(NameableObjectUtils.getUidDisplayPropertyMap(unit.getAncestors(), params.getDisplayProperty()));
            }
        }
        map.put(dimension.getDimension(), dimension.getDisplayProperty(params.getDisplayProperty()));
    }
    return map;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Calendar(org.hisp.dhis.calendar.Calendar) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Period(org.hisp.dhis.period.Period) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 53 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.

the class IdentifiableObjectUtils method getLocalPeriodIdentifiers.

/**
 * 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;
}
Also used : ArrayList(java.util.ArrayList) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Period(org.hisp.dhis.period.Period)

Example 54 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.

the class QuarterlyPeriodType method generateRollingPeriods.

@Override
public List<Period> generateRollingPeriods(DateTimeUnit dateTimeUnit, Calendar calendar) {
    dateTimeUnit.setDay(1);
    DateTimeUnit iterationDateTimeUnit = calendar.minusMonths(dateTimeUnit, 9);
    List<Period> periods = Lists.newArrayList();
    for (int i = 0; i < 4; i++) {
        periods.add(createPeriod(iterationDateTimeUnit, calendar));
        iterationDateTimeUnit = calendar.plusMonths(iterationDateTimeUnit, 3);
    }
    return periods;
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit)

Example 55 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.

the class QuarterlyPeriodType method getRewindedDate.

@Override
public Date getRewindedDate(Date date, Integer rewindedPeriods) {
    Calendar cal = getCalendar();
    date = date != null ? date : new Date();
    rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
    DateTimeUnit dateTimeUnit = createLocalDateUnitInstance(date);
    dateTimeUnit = cal.minusMonths(dateTimeUnit, rewindedPeriods * 3);
    return cal.toIso(dateTimeUnit).toJdkDate();
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Date(java.util.Date)

Aggregations

DateTimeUnit (org.hisp.dhis.calendar.DateTimeUnit)98 Calendar (org.hisp.dhis.calendar.Calendar)23 Test (org.junit.jupiter.api.Test)17 Date (java.util.Date)15 DateInterval (org.hisp.dhis.calendar.DateInterval)10 Period (org.hisp.dhis.period.Period)6 DateTime (org.joda.time.DateTime)5 LocalDate (java.time.LocalDate)4 DimensionalObject (org.hisp.dhis.common.DimensionalObject)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 ArrayList (java.util.ArrayList)3 WeekFields (java.time.temporal.WeekFields)2 HashMap (java.util.HashMap)2 Matcher (java.util.regex.Matcher)2 InvalidCalendarParametersException (org.hisp.dhis.calendar.exception.InvalidCalendarParametersException)2 DataDimensionalItemObject (org.hisp.dhis.common.DataDimensionalItemObject)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)2 DateUtils.getMediumDateString (org.hisp.dhis.util.DateUtils.getMediumDateString)2