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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations