Search in sources :

Example 26 with Calendar

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

the class MonthlyPeriodType 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 = cal.fromIso(DateTimeUnit.fromJdkDate(date));
    dateTimeUnit = cal.minusMonths(dateTimeUnit, rewindedPeriods);
    return cal.toIso(dateTimeUnit).toJdkDate();
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Date(java.util.Date)

Example 27 with Calendar

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

the class WeeklyAbstractPeriodType method generatePeriods.

/**
     * Generates weekly Periods for the whole year in which the given Period's
     * startDate exists.
     */
@Override
public List<Period> generatePeriods(DateTimeUnit start) {
    Calendar calendar = getCalendar();
    List<Period> periods = new ArrayList<>();
    start = adjustToStartOfWeek(start, calendar);
    for (int i = 0; i < calendar.weeksInYear(start.getYear()); i++) {
        DateInterval interval = calendar.toInterval(start, DateIntervalType.ISO8601_WEEK);
        periods.add(new Period(this, interval.getFrom().toJdkDate(), interval.getTo().toJdkDate()));
        start = calendar.plusWeeks(start, 1);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar) ArrayList(java.util.ArrayList) DateInterval(org.hisp.dhis.calendar.DateInterval)

Example 28 with Calendar

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

the class YearlyPeriodType method getRewindedDate.

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

Example 29 with Calendar

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

the class YearlyPeriodType method generateLast5Years.

/**
     * Generates the last 5 years where the last one is the year which the given
     * date is inside.
     */
@Override
public List<Period> generateLast5Years(Date date) {
    Calendar calendar = getCalendar();
    DateTimeUnit dateTimeUnit = createLocalDateUnitInstance(date);
    dateTimeUnit = calendar.minusYears(dateTimeUnit, 4);
    dateTimeUnit.setDay(1);
    dateTimeUnit.setMonth(1);
    List<Period> periods = Lists.newArrayList();
    for (int i = 0; i < 5; ++i) {
        periods.add(createPeriod(dateTimeUnit, calendar));
        dateTimeUnit = calendar.plusYears(dateTimeUnit, 1);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit)

Example 30 with Calendar

use of org.hisp.dhis.calendar.Calendar 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)

Aggregations

Calendar (org.hisp.dhis.calendar.Calendar)36 DateTimeUnit (org.hisp.dhis.calendar.DateTimeUnit)14 Date (java.util.Date)10 Period (org.hisp.dhis.period.Period)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 ArrayList (java.util.ArrayList)5 DimensionalObject (org.hisp.dhis.common.DimensionalObject)4 PeriodType (org.hisp.dhis.period.PeriodType)4 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)3 AnalyticsTable (org.hisp.dhis.analytics.AnalyticsTable)2 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)2 ReportTable (org.hisp.dhis.reporttable.ReportTable)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1