Search in sources :

Example 16 with DateTimeUnit

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

Example 17 with DateTimeUnit

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

Example 18 with DateTimeUnit

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

Example 19 with DateTimeUnit

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

Example 20 with DateTimeUnit

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

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