use of java.time.chrono.ChronoPeriod in project j2objc by google.
the class TCKChronoPeriod method test_minus.
/* J2ObjC removed: Only "gregorian" and "julian" calendars are supported.
@Test(expected=DateTimeException.class)
@UseDataProvider("data_of_calendars")
public void test_plus_wrongChrono(Chronology chrono) {
ChronoPeriod period = chrono.period(1, 2, 3);
ChronoPeriod isoPeriod = Period.of(2, 3, 4);
ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
// one of these two will fail
period.plus(isoPeriod);
period.plus(thaiPeriod);
} */
@Test()
@UseDataProvider("data_of_calendars")
public void test_minus(Chronology chrono) {
ChronoPeriod period = chrono.period(1, 2, 3);
ChronoPeriod period2 = chrono.period(2, 3, 4);
ChronoPeriod result = period.minus(period2);
assertEquals(result, chrono.period(-1, -1, -1));
}
use of java.time.chrono.ChronoPeriod in project j2objc by google.
the class TCKChronoPeriod method test_equals_equal.
// -----------------------------------------------------------------------
@Test()
@UseDataProvider("data_of_calendars")
public void test_equals_equal(Chronology chrono) {
ChronoPeriod a1 = chrono.period(1, 2, 3);
ChronoPeriod a2 = chrono.period(1, 2, 3);
assertEquals(a1, a1);
assertEquals(a1, a2);
assertEquals(a2, a1);
assertEquals(a2, a2);
assertEquals(a1.hashCode(), a2.hashCode());
}
use of java.time.chrono.ChronoPeriod in project j2objc by google.
the class TCKChronoPeriod method test_addTo.
/* J2ObjC removed: Only "gregorian" and "julian" calendars are supported.
@Test(expected=DateTimeException.class)
@UseDataProvider("data_of_calendars")
public void test_minus_wrongChrono(Chronology chrono) {
ChronoPeriod period = chrono.period(1, 2, 3);
ChronoPeriod isoPeriod = Period.of(2, 3, 4);
ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
// one of these two will fail
period.minus(isoPeriod);
period.minus(thaiPeriod);
} */
// -----------------------------------------------------------------------
@Test()
@UseDataProvider("data_of_calendars")
public void test_addTo(Chronology chrono) {
ChronoPeriod period = chrono.period(1, 2, 3);
ChronoLocalDate date = chrono.dateNow();
Temporal result = period.addTo(date);
assertEquals(result, date.plus(14, MONTHS).plus(3, DAYS));
}
use of java.time.chrono.ChronoPeriod in project drools by kiegroup.
the class InstanceOfNode method evaluate.
@Override
public Object evaluate(EvaluationContext ctx) {
Object value = expression.evaluate(ctx);
Type t = type.evaluate(ctx);
if (t != BuiltInType.DURATION) {
return t.isInstanceOf(value);
} else {
switch(type.getText()) {
case SimpleType.YEARS_AND_MONTHS_DURATION:
return value instanceof ChronoPeriod;
case SimpleType.DAYS_AND_TIME_DURATION:
return value instanceof Duration;
default:
return t.isInstanceOf(value);
}
}
}
use of java.time.chrono.ChronoPeriod in project drools by kiegroup.
the class EvalHelper method isEqual.
/**
* Compares left and right for equality applying FEEL semantics to specific data types
*
* @param left
* @param right
* @param ctx
* @return
*/
public static Boolean isEqual(Object left, Object right, EvaluationContext ctx) {
if (left == null || right == null) {
return left == right;
}
// and vice-versa
if (left instanceof Collection && !(right instanceof Collection) && ((Collection) left).size() == 1) {
left = ((Collection) left).toArray()[0];
} else if (right instanceof Collection && !(left instanceof Collection) && ((Collection) right).size() == 1) {
right = ((Collection) right).toArray()[0];
}
if (left instanceof Range && right instanceof Range) {
return isEqual((Range) left, (Range) right);
} else if (left instanceof Iterable && right instanceof Iterable) {
return isEqual((Iterable) left, (Iterable) right);
} else if (left instanceof Map && right instanceof Map) {
return isEqual((Map) left, (Map) right);
} else if (left instanceof ChronoPeriod && right instanceof ChronoPeriod) {
// periods have special compare semantics in FEEL as it ignores "days". Only months and years are compared
Long l = ComparablePeriod.toTotalMonths((ChronoPeriod) left);
Long r = ComparablePeriod.toTotalMonths((ChronoPeriod) right);
return isEqual(l, r);
} else if (left instanceof TemporalAccessor && right instanceof TemporalAccessor) {
// Handle specific cases when both time / datetime
TemporalAccessor l = (TemporalAccessor) left;
TemporalAccessor r = (TemporalAccessor) right;
if (BuiltInType.determineTypeFromInstance(left) == BuiltInType.TIME && BuiltInType.determineTypeFromInstance(right) == BuiltInType.TIME) {
return isEqual(valuet(l), valuet(r));
} else if (BuiltInType.determineTypeFromInstance(left) == BuiltInType.DATE_TIME && BuiltInType.determineTypeFromInstance(right) == BuiltInType.DATE_TIME) {
return isEqual(valuedt(l, r.query(TemporalQueries.zone())), valuedt(r, l.query(TemporalQueries.zone())));
}
// fallback; continue:
}
return compare(left, right, ctx, (l, r) -> l.compareTo(r) == 0);
}
Aggregations