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