Search in sources :

Example 31 with DateTimeUnit

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

Example 32 with DateTimeUnit

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

Example 33 with DateTimeUnit

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

Example 34 with DateTimeUnit

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

Example 35 with DateTimeUnit

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));
}
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