use of org.hisp.dhis.calendar.DateInterval in project dhis2-core by dhis2.
the class NepaliCalendar method toYearIsoInterval.
private DateInterval toYearIsoInterval(DateTimeUnit dateTimeUnit, int offset, int length) {
DateTimeUnit from = new DateTimeUnit(dateTimeUnit);
if (offset > 0) {
from = plusYears(from, offset);
} else if (offset < 0) {
from = minusYears(from, -offset);
}
DateTimeUnit to = new DateTimeUnit(from);
to = plusYears(to, length);
to = minusDays(to, length);
from = toIso(from);
to = toIso(to);
return new DateInterval(from, to, DateIntervalType.ISO8601_YEAR);
}
use of org.hisp.dhis.calendar.DateInterval in project dhis2-core by dhis2.
the class NepaliCalendar method toWeekIsoInterval.
private DateInterval toWeekIsoInterval(DateTimeUnit dateTimeUnit, int offset, int length) {
DateTimeUnit from = new DateTimeUnit(dateTimeUnit);
if (offset > 0) {
from = plusWeeks(from, offset);
} else if (offset < 0) {
from = minusWeeks(from, -offset);
}
DateTimeUnit to = new DateTimeUnit(from);
to = plusWeeks(to, length);
to = minusDays(to, 1);
from = toIso(from);
to = toIso(to);
return new DateInterval(from, to, DateIntervalType.ISO8601_WEEK);
}
use of org.hisp.dhis.calendar.DateInterval in project dhis2-core by dhis2.
the class NepaliCalendar method toDayIsoInterval.
private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int length) {
DateTimeUnit from = new DateTimeUnit(dateTimeUnit);
if (offset > 0) {
from = plusDays(from, offset);
} else if (offset < 0) {
from = minusDays(from, -offset);
}
DateTimeUnit to = new DateTimeUnit(from);
to = plusDays(to, length);
from = toIso(from);
to = toIso(to);
return new DateInterval(from, to, DateIntervalType.ISO8601_DAY);
}
use of org.hisp.dhis.calendar.DateInterval in project dhis2-core by dhis2.
the class WeeklyAbstractPeriodType method generatePeriods.
/**
* Generates 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<>();
start = adjustToStartOfWeek(start, calendar);
for (int i = 0; i < calendar.weeksInYear(start.getYear()); i++) {
DateInterval interval = calendar.toInterval(start, DateIntervalType.ISO8601_WEEK);
periods.add(new Period(this, interval.getFrom().toJdkDate(), interval.getTo().toJdkDate()));
start = calendar.plusWeeks(start, 1);
}
return periods;
}
use of org.hisp.dhis.calendar.DateInterval in project dhis2-core by dhis2.
the class PersianCalendarTest method testToInterval.
@Test
public void testToInterval() {
DateTimeUnit start = new DateTimeUnit(1373, 6, 1, java.util.Calendar.FRIDAY);
DateInterval interval = calendar.toInterval(start, DateIntervalType.ISO8601_DAY, 0, 10);
assertEquals(1994, interval.getTo().getYear());
assertEquals(9, interval.getTo().getMonth());
assertEquals(2, interval.getTo().getDay());
}
Aggregations