Search in sources :

Example 91 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.

the class NepaliCalendar method toWeekIsoInterval.

private DateInterval toWeekIsoInterval(DateTimeUnit dateTimeUnit, int offset, int length) {
    DateTimeUnit from = new DateTimeUnit(dateTimeUnit);
    if (offset > 0) {
        from = plusWeeks(from, offset);
    } else if (offset < 0) {
        from = minusWeeks(from, -offset);
    }
    DateTimeUnit to = new DateTimeUnit(from);
    to = plusWeeks(to, length);
    to = minusDays(to, 1);
    from = toIso(from);
    to = toIso(to);
    return new DateInterval(from, to, DateIntervalType.ISO8601_WEEK);
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) DateInterval(org.hisp.dhis.calendar.DateInterval)

Example 92 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.

the class NepaliCalendar method toMonthIsoInterval.

private DateInterval toMonthIsoInterval(DateTimeUnit dateTimeUnit, int offset, int length) {
    DateTimeUnit from = new DateTimeUnit(dateTimeUnit);
    if (offset > 0) {
        from = plusMonths(from, offset);
    } else if (offset < 0) {
        from = minusMonths(from, -offset);
    }
    DateTimeUnit to = new DateTimeUnit(from);
    to = plusMonths(to, length);
    to = minusDays(to, 1);
    from = toIso(from);
    to = toIso(to);
    return new DateInterval(from, to, DateIntervalType.ISO8601_MONTH);
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) DateInterval(org.hisp.dhis.calendar.DateInterval)

Example 93 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.

the class NepaliCalendar method toYearIsoInterval.

private DateInterval toYearIsoInterval(DateTimeUnit dateTimeUnit, int offset, int length) {
    DateTimeUnit from = new DateTimeUnit(dateTimeUnit);
    if (offset > 0) {
        from = plusYears(from, offset);
    } else if (offset < 0) {
        from = minusYears(from, -offset);
    }
    DateTimeUnit to = new DateTimeUnit(from);
    to = plusYears(to, length);
    to = minusDays(to, length);
    from = toIso(from);
    to = toIso(to);
    return new DateInterval(from, to, DateIntervalType.ISO8601_YEAR);
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) DateInterval(org.hisp.dhis.calendar.DateInterval)

Example 94 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.

the class NepaliCalendar method minusMonths.

@Override
public DateTimeUnit minusMonths(DateTimeUnit dateTimeUnit, int months) {
    DateTimeUnit result = new DateTimeUnit(dateTimeUnit);
    while (months != 0) {
        result.setMonth(result.getMonth() - 1);
        if (result.getMonth() < 1) {
            result.setMonth(monthsInYear());
            result.setYear(result.getYear() - 1);
        }
        months--;
    }
    updateDateUnit(result);
    return result;
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit)

Example 95 with DateTimeUnit

use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.

the class NepaliCalendar method plusYears.

@Override
public DateTimeUnit plusYears(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