Search in sources :

Example 56 with Period

use of java.time.Period in project drools by kiegroup.

the class RangeNode method convertToComparable.

private Comparable convertToComparable(EvaluationContext ctx, Object s) {
    Comparable start;
    if (s == null) {
        start = null;
    } else if (s instanceof Comparable) {
        start = (Comparable) s;
    } else if (s instanceof Period) {
        // period has special semantics
        start = new ComparablePeriod((Period) s);
    } else {
        ctx.notifyEvt(astEvent(Severity.ERROR, Msg.createMessage(Msg.INCOMPATIBLE_TYPE_FOR_RANGE, s.getClass().getSimpleName())));
        start = null;
    }
    return start;
}
Also used : ComparablePeriod(org.kie.dmn.feel.lang.types.impl.ComparablePeriod) Period(java.time.Period) ComparablePeriod(org.kie.dmn.feel.lang.types.impl.ComparablePeriod)

Example 57 with Period

use of java.time.Period in project mapstruct by mapstruct.

the class Java8TimeConversionTest method testStringToPeriodNullMapping.

@ProcessorTest
public void testStringToPeriodNullMapping() {
    Target target = new Target();
    target.setForPeriodConversionWithString(null);
    Source source = SourceTargetMapper.INSTANCE.targetToSource(target);
    Period period = source.getForPeriodConversionWithString();
    assertThat(period).isNull();
}
Also used : Period(java.time.Period) GeneratedSource(org.mapstruct.ap.testutil.runner.GeneratedSource) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 58 with Period

use of java.time.Period in project jdk8u_jdk by JetBrains.

the class TCKPeriod method test_hashCode.

//-----------------------------------------------------------------------
public void test_hashCode() {
    Period test5 = Period.ofDays(5);
    Period test6 = Period.ofDays(6);
    Period test5M = Period.ofMonths(5);
    Period test5Y = Period.ofYears(5);
    assertEquals(test5.hashCode() == test5.hashCode(), true);
    assertEquals(test5.hashCode() == test6.hashCode(), false);
}
Also used : Period(java.time.Period)

Example 59 with Period

use of java.time.Period in project jdk8u_jdk by JetBrains.

the class TCKPeriod method test_bad_getUnit.

@Test(dataProvider = "BadTemporalUnit", expectedExceptions = DateTimeException.class)
public void test_bad_getUnit(TemporalUnit unit) {
    Period period = Period.of(2, 2, 2);
    period.get(unit);
}
Also used : Period(java.time.Period) Test(org.testng.annotations.Test)

Example 60 with Period

use of java.time.Period in project jdk8u_jdk by JetBrains.

the class TCKPeriod method test_equals_otherClass.

public void test_equals_otherClass() {
    Period test = Period.of(1, 2, 3);
    assertEquals(test.equals(""), false);
}
Also used : Period(java.time.Period)

Aggregations

Period (java.time.Period)110 Test (org.junit.Test)37 Test (org.testng.annotations.Test)27 LocalDate (java.time.LocalDate)21 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)8 Duration (java.time.Duration)8 LocalDateTime (java.time.LocalDateTime)7 ZonedDateTime (java.time.ZonedDateTime)7 DateTimeFormatter (java.time.format.DateTimeFormatter)6 Date (java.util.Date)6 Instant (java.time.Instant)5 LocalTime (java.time.LocalTime)5 ZoneId (java.time.ZoneId)5 Test (org.junit.jupiter.api.Test)5 DateTimeParseException (java.time.format.DateTimeParseException)4 TemporalAmount (java.time.temporal.TemporalAmount)4 Arrays (java.util.Arrays)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 OffsetTime (java.time.OffsetTime)3