Search in sources :

Example 1 with Calendar

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

the class WeeklyAbstractPeriodType method generateRollingPeriods.

/**
     * Generates the last 52 weeks where the last one is the week which the
     * given date is inside.
     */
@Override
public List<Period> generateRollingPeriods(DateTimeUnit end) {
    Calendar calendar = getCalendar();
    List<Period> periods = Lists.newArrayList();
    end = adjustToStartOfWeek(end, calendar);
    end = calendar.minusDays(end, 357);
    for (int i = 0; i < 52; i++) {
        periods.add(createPeriod(end, calendar));
        end = calendar.plusWeeks(end, 1);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar)

Example 2 with Calendar

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

the class WeeklyAbstractPeriodType 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.minusWeeks(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 3 with Calendar

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

the class YearlyPeriodType method generatePeriods.

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

Example 4 with Calendar

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

the class BiMonthlyPeriodType 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 5 with Calendar

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

the class BiMonthlyPeriodType method generatePeriods.

/**
     * Generates bimonthly Periods for the whole year in which the start date of
     * the given Period exists.
     */
@Override
public List<Period> generatePeriods(DateTimeUnit dateTimeUnit) {
    Calendar cal = getCalendar();
    dateTimeUnit.setMonth(1);
    dateTimeUnit.setDay(1);
    List<Period> periods = Lists.newArrayList();
    int year = dateTimeUnit.getYear();
    while (dateTimeUnit.getYear() == year) {
        periods.add(createPeriod(dateTimeUnit, cal));
        dateTimeUnit = cal.plusMonths(dateTimeUnit, 2);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar)

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