Search in sources :

Example 81 with DateTimeUnit

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)));
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Test(org.junit.jupiter.api.Test)

Example 82 with DateTimeUnit

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());
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Test(org.junit.jupiter.api.Test)

Example 83 with DateTimeUnit

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());
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Test(org.junit.jupiter.api.Test)

Example 84 with DateTimeUnit

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());
}
Also used : InvalidCalendarParametersException(org.hisp.dhis.calendar.exception.InvalidCalendarParametersException) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) DateTime(org.joda.time.DateTime)

Example 85 with DateTimeUnit

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;
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit)

Aggregations

DateTimeUnit (org.hisp.dhis.calendar.DateTimeUnit)98 Calendar (org.hisp.dhis.calendar.Calendar)23 Test (org.junit.jupiter.api.Test)17 Date (java.util.Date)15 DateInterval (org.hisp.dhis.calendar.DateInterval)10 Period (org.hisp.dhis.period.Period)6 DateTime (org.joda.time.DateTime)5 LocalDate (java.time.LocalDate)4 DimensionalObject (org.hisp.dhis.common.DimensionalObject)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 ArrayList (java.util.ArrayList)3 WeekFields (java.time.temporal.WeekFields)2 HashMap (java.util.HashMap)2 Matcher (java.util.regex.Matcher)2 InvalidCalendarParametersException (org.hisp.dhis.calendar.exception.InvalidCalendarParametersException)2 DataDimensionalItemObject (org.hisp.dhis.common.DataDimensionalItemObject)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)2 DateUtils.getMediumDateString (org.hisp.dhis.util.DateUtils.getMediumDateString)2