use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class MonthlyPeriodType method generateRollingPeriods.
/**
* Generates the last 12 months where the last one is the month which the
* given date is inside.
*/
@Override
public List<Period> generateRollingPeriods(DateTimeUnit dateTimeUnit, Calendar calendar) {
dateTimeUnit.setDay(1);
DateTimeUnit iterationDateTimeUnit = calendar.minusMonths(dateTimeUnit, 11);
List<Period> periods = Lists.newArrayList();
for (int i = 0; i < 12; i++) {
periods.add(createPeriod(iterationDateTimeUnit, calendar));
iterationDateTimeUnit = calendar.plusMonths(iterationDateTimeUnit, 1);
}
return periods;
}
use of org.hisp.dhis.calendar.DateTimeUnit 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 * 2);
return cal.toIso(dateTimeUnit).toJdkDate();
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class PeriodType method toIsoPeriod.
protected Period toIsoPeriod(DateTimeUnit start, DateTimeUnit end, org.hisp.dhis.calendar.Calendar calendar) {
DateTimeUnit from = calendar.toIso(start);
DateTimeUnit to = calendar.toIso(end);
return new Period(this, from.toJdkDate(), to.toJdkDate(), getIsoDate(start, calendar));
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class QuarterlyPeriodType method createPeriod.
@Override
public Period createPeriod(DateTimeUnit dateTimeUnit, Calendar calendar) {
DateTimeUnit start = new DateTimeUnit(dateTimeUnit);
start.setMonth(((dateTimeUnit.getMonth() - 1) - ((dateTimeUnit.getMonth() - 1) % 3)) + 1);
start.setDay(1);
if (start.getMonth() > 12) {
start.setYear(start.getYear() + 1);
start.setMonth(1);
}
DateTimeUnit end = new DateTimeUnit(start);
end = calendar.plusMonths(end, 2);
end.setDay(calendar.daysInMonth(end.getYear(), end.getMonth()));
return toIsoPeriod(start, end, calendar);
}
use of org.hisp.dhis.calendar.DateTimeUnit 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) {
List<Period> periods = Lists.newArrayList();
DateTimeUnit iterationDateTimeUnit = adjustToStartOfWeek(end, calendar);
iterationDateTimeUnit = calendar.minusDays(iterationDateTimeUnit, 357);
for (int i = 0; i < 52; i++) {
periods.add(createPeriod(iterationDateTimeUnit, calendar));
iterationDateTimeUnit = calendar.plusWeeks(iterationDateTimeUnit, 1);
}
return periods;
}
Aggregations