Search in sources :

Example 36 with DateTimeUnit

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

the class PersianCalendarTest method testToIso.

@Test
void testToIso() {
    assertEquals(new DateTimeUnit(1993, 3, 21, true), calendar.toIso(new DateTimeUnit(1372, 1, 1)));
    assertEquals(new DateTimeUnit(2020, 3, 20, true), calendar.toIso(new DateTimeUnit(1399, 1, 1)));
    assertEquals(new DateTimeUnit(2020, 3, 20, true), calendar.toIso(new DateTimeUnit(2020, 3, 20)));
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Test(org.junit.jupiter.api.Test)

Example 37 with DateTimeUnit

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

the class PersianCalendarTest method testMinusMonths.

@Test
void testMinusMonths() {
    DateTimeUnit dateTimeUnit = new DateTimeUnit(1382, 1, 20);
    DateTimeUnit testDateTimeUnit = calendar.minusMonths(dateTimeUnit, 1);
    assertEquals(1381, testDateTimeUnit.getYear());
    assertEquals(12, testDateTimeUnit.getMonth());
    assertEquals(20, testDateTimeUnit.getDay());
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Test(org.junit.jupiter.api.Test)

Example 38 with DateTimeUnit

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

the class PersianCalendarTest method testPlusWeeks.

@Test
void testPlusWeeks() {
    DateTimeUnit dateTimeUnit = new DateTimeUnit(1382, 1, 20);
    DateTimeUnit testDateTimeUnit = calendar.plusWeeks(dateTimeUnit, 4);
    assertEquals(1382, testDateTimeUnit.getYear());
    assertEquals(2, testDateTimeUnit.getMonth());
    assertEquals(17, testDateTimeUnit.getDay());
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Test(org.junit.jupiter.api.Test)

Example 39 with DateTimeUnit

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

the class DateUtils method dateIsValid.

/**
     * This method checks whether the String inDate is a valid date following
     * the format "yyyy-MM-dd".
     *
     * @param calendar   Calendar to be used
     * @param dateString the string to be checked.
     * @return true/false depending on whether the string is a date according to the format "yyyy-MM-dd".
     */
public static boolean dateIsValid(org.hisp.dhis.calendar.Calendar calendar, String dateString) {
    Matcher matcher = DEFAULT_DATE_REGEX_PATTERN.matcher(dateString);
    if (!matcher.matches()) {
        return false;
    }
    DateTimeUnit dateTime = new DateTimeUnit(Integer.valueOf(matcher.group("year")), Integer.valueOf(matcher.group("month")), Integer.valueOf(matcher.group("day")));
    return calendar.isValid(dateTime);
}
Also used : Matcher(java.util.regex.Matcher) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit)

Example 40 with DateTimeUnit

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

the class BiMonthlyPeriodType method getNextPeriod.

// -------------------------------------------------------------------------
// CalendarPeriodType functionality
// -------------------------------------------------------------------------
@Override
public Period getNextPeriod(Period period, Calendar calendar) {
    DateTimeUnit dateTimeUnit = calendar.fromIso(DateTimeUnit.fromJdkDate(period.getStartDate()));
    dateTimeUnit = calendar.plusMonths(dateTimeUnit, 2);
    return createPeriod(dateTimeUnit, calendar);
}
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