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