Search in sources :

Example 86 with DateTimeException

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

the class HourDiffFunction method invoke.

public FEELFnResult<BigDecimal> invoke(@ParameterName("datetime1") String datetime1, @ParameterName("datetime2") String datetime2) {
    if (datetime1 == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime1", "cannot be null"));
    }
    if (datetime2 == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime2", "cannot be null"));
    }
    try {
        TemporalAccessor dt1 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime1).cata(BuiltInType.justNull(), Function.identity());
        TemporalAccessor dt2 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime2).cata(BuiltInType.justNull(), Function.identity());
        return invoke(dt1, dt2);
    } catch (DateTimeException e) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime", "invalid 'date' or 'date and time' parameter", e));
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeException(java.time.DateTimeException) InvalidParametersEvent(org.kie.dmn.feel.runtime.events.InvalidParametersEvent)

Example 87 with DateTimeException

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

the class MinutesDiffFunction method invoke.

public FEELFnResult<BigDecimal> invoke(@ParameterName("datetime1") String datetime1, @ParameterName("datetime2") String datetime2) {
    if (datetime1 == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime1", "cannot be null"));
    }
    if (datetime2 == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime2", "cannot be null"));
    }
    try {
        TemporalAccessor dt1 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime1).cata(BuiltInType.justNull(), Function.identity());
        TemporalAccessor dt2 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime2).cata(BuiltInType.justNull(), Function.identity());
        return invoke(dt1, dt2);
    } catch (DateTimeException e) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime", "invalid 'date' or 'date and time' parameter", e));
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeException(java.time.DateTimeException) InvalidParametersEvent(org.kie.dmn.feel.runtime.events.InvalidParametersEvent)

Example 88 with DateTimeException

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

the class MonthDiffFunction method invoke.

public FEELFnResult<BigDecimal> invoke(@ParameterName("datetime1") String datetime1, @ParameterName("datetime2") String datetime2) {
    if (datetime1 == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime1", "cannot be null"));
    }
    if (datetime2 == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime2", "cannot be null"));
    }
    try {
        TemporalAccessor dt1 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime1).cata(BuiltInType.justNull(), Function.identity());
        TemporalAccessor dt2 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime2).cata(BuiltInType.justNull(), Function.identity());
        return invoke(dt1, dt2);
    } catch (DateTimeException e) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime", "invalid 'date' or 'date and time' parameter", e));
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeException(java.time.DateTimeException) InvalidParametersEvent(org.kie.dmn.feel.runtime.events.InvalidParametersEvent)

Aggregations

DateTimeException (java.time.DateTimeException)88 Test (org.testng.annotations.Test)58 TemporalField (java.time.temporal.TemporalField)48 HashMap (java.util.HashMap)34 LocalDate (java.time.LocalDate)20 TemporalAccessor (java.time.temporal.TemporalAccessor)20 DateTimeFormatter (java.time.format.DateTimeFormatter)13 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)10 MinguoDate (java.time.chrono.MinguoDate)7 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)7 InvalidParametersEvent (org.kie.dmn.feel.runtime.events.InvalidParametersEvent)7 MockFieldValue (test.java.time.temporal.MockFieldValue)7 HijrahDate (java.time.chrono.HijrahDate)6 ChronoLocalDate (java.time.chrono.ChronoLocalDate)5 JapaneseDate (java.time.chrono.JapaneseDate)5 Chronology (java.time.chrono.Chronology)4 IOException (java.io.IOException)3 LocalTime (java.time.LocalTime)3 WeekFields (java.time.temporal.WeekFields)3 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)3