use of org.hisp.dhis.calendar.DateTimeUnit 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.DateTimeUnit in project dhis2-core by dhis2.
the class SixMonthlyAbstractPeriodType 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.minusMonths(dateTimeUnit, rewindedPeriods * 6);
return cal.toIso(dateTimeUnit).toJdkDate();
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class YearlyPeriodType method createPeriod.
@Override
public Period createPeriod(DateTimeUnit dateTimeUnit, Calendar calendar) {
DateTimeUnit start = new DateTimeUnit(dateTimeUnit);
DateTimeUnit end = new DateTimeUnit(dateTimeUnit);
start.setDay(1);
start.setMonth(1);
end.setMonth(calendar.monthsInYear());
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 NepaliCalendarTest method testPlusDays.
@Test
void testPlusDays() {
DateTimeUnit dateTimeUnit = new DateTimeUnit(2014, 12, 30);
DateTimeUnit testDateTimeUnit = calendar.plusDays(dateTimeUnit, -1);
assertEquals(2014, testDateTimeUnit.getYear());
assertEquals(12, testDateTimeUnit.getMonth());
assertEquals(29, testDateTimeUnit.getDay());
dateTimeUnit = new DateTimeUnit(2014, 1, 1);
testDateTimeUnit = calendar.plusDays(dateTimeUnit, -1);
assertEquals(2013, testDateTimeUnit.getYear());
assertEquals(12, testDateTimeUnit.getMonth());
assertEquals(30, testDateTimeUnit.getDay());
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class NepaliCalendarTest method testToIso.
@Test
void testToIso() {
Assertions.assertEquals(new DateTimeUnit(2014, 4, 14, true), calendar.toIso(new DateTimeUnit(2071, 1, 1)));
Assertions.assertEquals(new DateTimeUnit(2014, 4, 14, true), calendar.toIso(2071, 1, 1));
}
Aggregations