use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class PersianCalendarTest method testFromIso.
@Test
void testFromIso() {
assertEquals(new DateTimeUnit(1372, 1, 1, false), calendar.fromIso(new DateTimeUnit(1993, 3, 21, true)));
assertEquals(new DateTimeUnit(1399, 1, 1, false), calendar.fromIso(new DateTimeUnit(2020, 3, 20, true)));
assertEquals(new DateTimeUnit(1383, 1, 1, false), calendar.fromIso(new DateTimeUnit(2004, 3, 20, true)));
assertEquals(new DateTimeUnit(1383, 1, 1, false), calendar.fromIso(new DateTimeUnit(1383, 1, 1, true)));
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class PersianCalendarTest method testPlusDays.
@Test
void testPlusDays() {
DateTimeUnit dateTimeUnit = new DateTimeUnit(1382, 1, 1);
DateTimeUnit testDateTimeUnit = calendar.plusDays(dateTimeUnit, 31);
assertEquals(1382, testDateTimeUnit.getYear());
assertEquals(2, testDateTimeUnit.getMonth());
assertEquals(1, testDateTimeUnit.getDay());
testDateTimeUnit = calendar.plusDays(dateTimeUnit, 366);
assertEquals(1383, testDateTimeUnit.getYear());
assertEquals(1, testDateTimeUnit.getMonth());
assertEquals(2, testDateTimeUnit.getDay());
dateTimeUnit = new DateTimeUnit(1403, 12, 29);
testDateTimeUnit = calendar.plusDays(dateTimeUnit, 1);
assertEquals(1403, testDateTimeUnit.getYear());
assertEquals(12, testDateTimeUnit.getMonth());
assertEquals(30, testDateTimeUnit.getDay());
dateTimeUnit = new DateTimeUnit(1403, 12, 30);
testDateTimeUnit = calendar.plusDays(dateTimeUnit, -1);
assertEquals(1403, testDateTimeUnit.getYear());
assertEquals(12, testDateTimeUnit.getMonth());
assertEquals(29, testDateTimeUnit.getDay());
dateTimeUnit = new DateTimeUnit(1371, 1, 1);
testDateTimeUnit = calendar.plusDays(dateTimeUnit, -1);
assertEquals(1370, 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 testIsoStartOfYear.
@Test
void testIsoStartOfYear() {
DateTimeUnit startOfYear = calendar.isoStartOfYear(1383);
assertEquals(2004, startOfYear.getYear());
assertEquals(3, startOfYear.getMonth());
assertEquals(20, startOfYear.getDay());
startOfYear = calendar.isoStartOfYear(1409);
assertEquals(2030, startOfYear.getYear());
assertEquals(3, startOfYear.getMonth());
assertEquals(21, startOfYear.getDay());
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class PersianCalendar method fromIso.
@Override
public DateTimeUnit fromIso(DateTimeUnit dateTimeUnit) {
if (dateTimeUnit.getYear() >= START_PERSIAN.getYear() && dateTimeUnit.getYear() <= STOP_PERSIAN.getYear()) {
return new DateTimeUnit(dateTimeUnit.getYear(), dateTimeUnit.getMonth(), dateTimeUnit.getDay(), dateTimeUnit.getDayOfWeek(), false);
}
if (dateTimeUnit.getYear() < START_ISO.getYear() || dateTimeUnit.getYear() > STOP_ISO.getYear()) {
throw new InvalidCalendarParametersException("Illegal ISO year, must be between " + START_ISO.getYear() + " and " + STOP_ISO.getYear() + ", was given " + dateTimeUnit.getYear());
}
DateTime start = START_ISO.toJodaDateTime();
DateTime end = dateTimeUnit.toJodaDateTime();
return plusDays(START_PERSIAN, Days.daysBetween(start, end).getDays());
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class PersianCalendar method minusYears.
@Override
public DateTimeUnit minusYears(DateTimeUnit dateTimeUnit, int years) {
DateTimeUnit result = new DateTimeUnit(dateTimeUnit.getYear() - years, dateTimeUnit.getMonth(), dateTimeUnit.getDay(), dateTimeUnit.getDayOfWeek());
updateDateUnit(result);
return result;
}
Aggregations