Search in sources :

Example 21 with Calendar

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

the class DailyPeriodType method generateRollingPeriods.

/**
     * Generates the last 365 days where the last one is the day of the given
     * date.
     */
@Override
public List<Period> generateRollingPeriods(DateTimeUnit dateTimeUnit) {
    Calendar cal = getCalendar();
    dateTimeUnit = cal.minusDays(dateTimeUnit, 364);
    List<Period> periods = Lists.newArrayList();
    for (int i = 0; i < 365; i++) {
        periods.add(createPeriod(dateTimeUnit, null));
        dateTimeUnit = cal.plusDays(dateTimeUnit, 1);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar)

Example 22 with Calendar

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

the class DailyPeriodType method generatePeriods.

/**
     * Generates daily Periods for the whole year in which the given Period's
     * startDate exists.
     */
@Override
public List<Period> generatePeriods(DateTimeUnit dateTimeUnit) {
    dateTimeUnit.setMonth(1);
    dateTimeUnit.setDay(1);
    List<Period> periods = Lists.newArrayList();
    int year = dateTimeUnit.getYear();
    Calendar calendar = getCalendar();
    while (year == dateTimeUnit.getYear()) {
        periods.add(createPeriod(dateTimeUnit, null));
        dateTimeUnit = calendar.plusDays(dateTimeUnit, 1);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar)

Example 23 with Calendar

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

the class FinancialPeriodType method generateLast5Years.

@Override
public List<Period> generateLast5Years(Date date) {
    Calendar cal = getCalendar();
    DateTimeUnit dateTimeUnit = createLocalDateUnitInstance(date, cal);
    boolean past = dateTimeUnit.getMonth() >= (getBaseMonth() + 1);
    List<Period> periods = Lists.newArrayList();
    dateTimeUnit = cal.minusYears(dateTimeUnit, past ? 4 : 5);
    dateTimeUnit.setMonth(getBaseMonth() + 1);
    dateTimeUnit.setDay(1);
    for (int i = 0; i < 5; i++) {
        periods.add(createPeriod(dateTimeUnit, cal));
        dateTimeUnit = cal.plusYears(dateTimeUnit, 1);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit)

Example 24 with Calendar

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

the class FinancialPeriodType method generatePeriods.

/**
     * Generates financial yearly periods for the last 5, current and next 5
     * financial years.
     */
@Override
public List<Period> generatePeriods(DateTimeUnit dateTimeUnit) {
    Calendar cal = getCalendar();
    boolean past = dateTimeUnit.getMonth() >= (getBaseMonth() + 1);
    List<Period> periods = Lists.newArrayList();
    dateTimeUnit = cal.minusYears(dateTimeUnit, past ? 5 : 6);
    dateTimeUnit.setMonth(getBaseMonth() + 1);
    dateTimeUnit.setDay(1);
    Calendar calendar = getCalendar();
    for (int i = 0; i < 11; i++) {
        periods.add(createPeriod(dateTimeUnit, cal));
        dateTimeUnit = calendar.plusYears(dateTimeUnit, 1);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar)

Example 25 with Calendar

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

the class FinancialPeriodType 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, cal);
    dateTimeUnit = cal.minusYears(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)

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