use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class EthiopianCalendarTest method testIsoStartOfYear.
@Test
void testIsoStartOfYear() {
DateTimeUnit startOfYear = calendar.isoStartOfYear(2007);
assertEquals(2014, startOfYear.getYear());
assertEquals(9, startOfYear.getMonth());
assertEquals(11, startOfYear.getDay());
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class EthiopianCalendarTest method testPlusDays.
@Test
void testPlusDays() {
DateTimeUnit dateTimeUnit = new DateTimeUnit(2006, 1, 1);
DateTimeUnit testDateTimeUnit = calendar.plusDays(dateTimeUnit, 43);
assertEquals(2006, testDateTimeUnit.getYear());
assertEquals(2, testDateTimeUnit.getMonth());
assertEquals(14, testDateTimeUnit.getDay());
testDateTimeUnit = calendar.plusDays(dateTimeUnit, 65);
assertEquals(2006, testDateTimeUnit.getYear());
assertEquals(3, testDateTimeUnit.getMonth());
assertEquals(6, testDateTimeUnit.getDay());
testDateTimeUnit = calendar.plusDays(dateTimeUnit, (12 * 30) + 5);
assertEquals(2007, testDateTimeUnit.getYear());
assertEquals(1, testDateTimeUnit.getMonth());
assertEquals(6, testDateTimeUnit.getDay());
dateTimeUnit = new DateTimeUnit(2006, 2, 29);
testDateTimeUnit = calendar.plusDays(dateTimeUnit, 10);
assertEquals(2006, testDateTimeUnit.getYear());
assertEquals(3, testDateTimeUnit.getMonth());
assertEquals(9, testDateTimeUnit.getDay());
dateTimeUnit = new DateTimeUnit(2006, 3, 9);
testDateTimeUnit = calendar.plusDays(dateTimeUnit, -1);
assertEquals(2006, testDateTimeUnit.getYear());
assertEquals(3, testDateTimeUnit.getMonth());
assertEquals(8, testDateTimeUnit.getDay());
dateTimeUnit = new DateTimeUnit(2006, 1, 1);
testDateTimeUnit = calendar.plusDays(dateTimeUnit, -1);
assertEquals(2005, 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 PersianCalendarTest method testPlusMonths.
@Test
void testPlusMonths() {
DateTimeUnit dateTimeUnit = new DateTimeUnit(1382, 1, 20);
DateTimeUnit testDateTimeUnit = calendar.plusMonths(dateTimeUnit, 4);
assertEquals(1382, testDateTimeUnit.getYear());
assertEquals(5, testDateTimeUnit.getMonth());
assertEquals(20, testDateTimeUnit.getDay());
dateTimeUnit = new DateTimeUnit(1382, 1, 20);
testDateTimeUnit = calendar.plusMonths(dateTimeUnit, -4);
assertEquals(1381, testDateTimeUnit.getYear());
assertEquals(9, testDateTimeUnit.getMonth());
assertEquals(20, testDateTimeUnit.getDay());
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class AnalyticsTableUpdateParams method getFromDate.
/**
* Returns the from date based on the last years property, i.e. the first
* day of year relative to the last years property.
*
* @return the from date based on the last years property.
*/
public Date getFromDate() {
Date earliest = null;
if (lastYears != null) {
Calendar calendar = PeriodType.getCalendar();
DateTimeUnit dateTimeUnit = today == null ? calendar.today() : DateTimeUnit.fromJdkDate(today);
dateTimeUnit = calendar.minusYears(dateTimeUnit, lastYears - 1);
dateTimeUnit.setMonth(1);
dateTimeUnit.setDay(1);
earliest = dateTimeUnit.toJdkDate();
}
return earliest;
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class WeeklyPeriodTypeTest method testGenerateWeeklyPeriodWithinAYear.
@Test
void testGenerateWeeklyPeriodWithinAYear() {
periodType = new WeeklyPeriodType();
List<Period> periods = periodType.generatePeriods(new DateTimeUnit(2019, 4, 1));
assertEquals(52, periods.size());
assertFalse(periodsInYear(periods, 2018));
assertFalse(periodsInYear(periods, 2019));
assertFalse(periodsInYear(periods, 2020));
assertEquals(2018, DateTimeUnit.fromJdkDate(periods.get(0).getStartDate()).getYear());
assertEquals(2019, DateTimeUnit.fromJdkDate(periods.get(1).getStartDate()).getYear());
periods = periodType.generatePeriods(new DateTimeUnit(2018, 1, 1));
assertEquals(52, periods.size());
assertFalse(periodsInYear(periods, 2017));
assertTrue(periodsInYear(periods, 2018));
assertFalse(periodsInYear(periods, 2019));
periods = periodType.generatePeriods(new DateTimeUnit(2015, 4, 1));
assertEquals(53, periods.size());
assertFalse(periodsInYear(periods, 2014));
assertFalse(periodsInYear(periods, 2015));
assertFalse(periodsInYear(periods, 2016));
assertEquals(2014, DateTimeUnit.fromJdkDate(periods.get(0).getStartDate()).getYear());
assertEquals(2015, DateTimeUnit.fromJdkDate(periods.get(1).getStartDate()).getYear());
periods = periodType.generatePeriods(new DateTimeUnit(1990, 1, 1));
assertEquals(52, periods.size());
assertFalse(periodsInYear(periods, 1989));
assertTrue(periodsInYear(periods, 1990));
assertFalse(periodsInYear(periods, 1991));
assertEquals(1990, DateTimeUnit.fromJdkDate(periods.get(0).getStartDate()).getYear());
periods = periodType.generatePeriods(new DateTimeUnit(1981, 1, 1));
assertEquals(53, periods.size());
assertFalse(periodsInYear(periods, 1980));
assertFalse(periodsInYear(periods, 1981));
assertFalse(periodsInYear(periods, 1982));
assertEquals(1980, DateTimeUnit.fromJdkDate(periods.get(0).getStartDate()).getYear());
assertEquals(1981, DateTimeUnit.fromJdkDate(periods.get(1).getStartDate()).getYear());
periods = periodType.generatePeriods(new DateTimeUnit(1980, 12, 29));
assertEquals(52, periods.size());
assertFalse(periodsInYear(periods, 1980));
assertFalse(periodsInYear(periods, 1980));
assertFalse(periodsInYear(periods, 1981));
assertEquals(1979, DateTimeUnit.fromJdkDate(periods.get(0).getStartDate()).getYear());
assertEquals(1980, DateTimeUnit.fromJdkDate(periods.get(1).getStartDate()).getYear());
}
Aggregations