Search in sources :

Example 61 with DateTimeUnit

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

the class BiWeeklyAbstractPeriodType method generatePeriods.

/**
 * Generates bi-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<>();
    DateTimeUnit date = adjustToStartOfBiWeek(start, calendar);
    date = adjustToStartOfBiWeek(calendar.fromIso(date.getYear(), 1, 1), calendar);
    for (int i = 0; i < calendar.weeksInYear(start.getYear()) / 2; i++) {
        periods.add(createPeriod(date, calendar));
        date = calendar.plusWeeks(date, 2);
    }
    return periods;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar) ArrayList(java.util.ArrayList) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit)

Example 62 with DateTimeUnit

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

the class DailyPeriodType 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.minusDays(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 63 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit 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 64 with DateTimeUnit

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

Example 65 with DateTimeUnit

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

the class FinancialPeriodType method createPeriod.

// -------------------------------------------------------------------------
// PeriodType functionality
// -------------------------------------------------------------------------
@Override
public Period createPeriod(DateTimeUnit dateTimeUnit, Calendar calendar) {
    boolean past = dateTimeUnit.getMonth() >= (getBaseMonth() + 1);
    if (!past) {
        dateTimeUnit = calendar.minusYears(dateTimeUnit, 1);
    }
    dateTimeUnit.setMonth(getBaseMonth() + 1);
    dateTimeUnit.setDay(1);
    DateTimeUnit start = new DateTimeUnit(dateTimeUnit);
    DateTimeUnit end = new DateTimeUnit(dateTimeUnit);
    end = calendar.plusYears(end, 1);
    end = calendar.minusDays(end, 1);
    return toIsoPeriod(start, end, calendar);
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit)

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