Tabnine Logo
DateAndTimeFunction
Code IndexAdd Tabnine to your IDE (free)

How to use
DateAndTimeFunction
in
org.kie.dmn.feel.runtime.functions

Best Java code snippets using org.kie.dmn.feel.runtime.functions.DateAndTimeFunction (Showing top 19 results out of 315)

origin: org.kie/kie-dmn-feel

@Test
public void invokeParamTemporalWrongTemporal() {
  // reminder: 1st parameter accordingly to FEEL Spec Table 58 "date is a date or date time [...] creates a date time from the given date (ignoring any time component)" [that means ignoring any TZ from `date` parameter, too]
  FunctionTestUtil.assertResultError(
      dateTimeFunction.invoke(
          LocalDate.of(2017, 6, 12),
          LocalDateTime.of(2017, 6, 12, 0, 0)), InvalidParametersEvent.class);
  FunctionTestUtil.assertResultError(
      dateTimeFunction.invoke(
          LocalDateTime.of(2017, 6, 12, 0, 0),
          LocalDateTime.of(2017, 6, 12, 0, 0)), InvalidParametersEvent.class);
}
origin: org.kie/kie-dmn-feel

@Before
public void setUp() {
  dateTimeFunction = new DateAndTimeFunction();
}
origin: org.kie/kie-dmn-feel

@Test
public void invokeParamStringDateTime() {
  FunctionTestUtil.assertResult(dateTimeFunction.invoke("2017-09-07T10:20:30"), LocalDateTime.of(2017, 9, 7, 10, 20, 30));
  FunctionTestUtil.assertResult(dateTimeFunction.invoke("99999-12-31T11:22:33"), LocalDateTime.of(99999, 12, 31, 11, 22, 33));
}
origin: org.kie/kie-dmn-feel

@Before
public void setUp() {
  dateTimeFunction = new DateAndTimeFunction();
  dateFunction = new DateFunction();
  timeFunction = new TimeFunction();
  stringFunction = new StringFunction();
}
origin: org.kie/kie-dmn-feel

@Test
public void invokeParamStringNotDateOrTime() {
  FunctionTestUtil.assertResultError(dateTimeFunction.invoke("test"), InvalidParametersEvent.class);
  FunctionTestUtil.assertResultError(dateTimeFunction.invoke("2017-09-test"), InvalidParametersEvent.class);
  FunctionTestUtil.assertResultError(dateTimeFunction.invoke("2017-09-T89"), InvalidParametersEvent.class);
}
origin: org.kie/kie-dmn-feel

@Test
public void invokeParamTemporalNulls() {
  FunctionTestUtil.assertResultError(dateTimeFunction.invoke((Temporal) null, null), InvalidParametersEvent.class);
  FunctionTestUtil.assertResultError(dateTimeFunction.invoke(null, LocalTime.of(10, 6, 20)), InvalidParametersEvent.class);
  FunctionTestUtil.assertResultError(dateTimeFunction.invoke(LocalDate.of(2017, 6, 12), null), InvalidParametersEvent.class);
}
origin: org.kie/kie-dmn-feel

@Test
public void invokeParamStringDate() {
  FunctionTestUtil.assertResult(dateTimeFunction.invoke("2017-09-07"), LocalDateTime.of(2017, 9, 7, 0, 0, 0));
}
origin: org.kie/kie-dmn-feel

  return BuiltInFunctions.getFunction( TimeFunction.class ).invoke( value ).cata( justNull(), Function.identity() );
} else if ( feelType.equals( org.kie.dmn.feel.lang.types.BuiltInType.DATE_TIME ) ) {
  return BuiltInFunctions.getFunction( DateAndTimeFunction.class ).invoke( value ).cata( justNull(), Function.identity() );
} else if ( feelType.equals( org.kie.dmn.feel.lang.types.BuiltInType.DURATION ) ) {
  return BuiltInFunctions.getFunction( DurationFunction.class ).invoke( value ).cata( justNull(), Function.identity() );
origin: org.kie/kie-dmn-feel

@Test
public void invokeParamTemporalLocalTime() {
  FunctionTestUtil.assertResult(
      dateTimeFunction.invoke(
          LocalDate.of(2017, 6, 12),
          LocalTime.of(10, 6, 20)),
      LocalDateTime.of(2017, 6, 12, 10, 6, 20));
}
origin: org.kie/kie-dmn-feel

  @Test
  public void invokeParamTemporalOffsetTime() {
    FunctionTestUtil.assertResult(
        dateTimeFunction.invoke(
            LocalDate.of(2017, 6, 12),
            OffsetTime.of(10, 6, 20, 0, ZoneOffset.UTC)),
        ZonedDateTime.of(2017, 6, 12, 10, 6, 20, 0, ZoneOffset.UTC));
  }
}
origin: org.kie/kie-dmn-feel

@Test
public void invokeParamStringNull() {
  FunctionTestUtil.assertResultError(dateTimeFunction.invoke(null), InvalidParametersEvent.class);
}
origin: org.kie/kie-dmn-feel

@Test
public void testComposite1() {
  final FEELFnResult<TemporalAccessor> p1 = dateTimeFunction.invoke("2017-08-10T10:20:00+02:00");
  final FEELFnResult<TemporalAccessor> p2 = timeFunction.invoke("23:59:01");
  FunctionTestUtil.assertResult(p1, ZonedDateTime.of(2017, 8, 10, 10, 20, 0, 0, ZoneId.of("+02:00")));
  FunctionTestUtil.assertResult(p2, LocalTime.of(23, 59, 1));
  final FEELFnResult<TemporalAccessor> result = dateTimeFunction.invoke(p1.getOrElse(null), p2.getOrElse(null));
  FunctionTestUtil.assertResult(result, LocalDateTime.of(2017, 8, 10, 23, 59, 1));
}
origin: org.kie/kie-dmn-feel

public FEELFnResult<TemporalAccessor> invoke(@ParameterName("from") String val) {
  if (val == null) {
    return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "cannot be null"));
  }
  if (!BEGIN_YEAR.matcher(val).find()) { // please notice the regex strictly requires the beginning, so we can use find.
    return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "year not compliant with XML Schema Part 2 Datatypes"));
  }
  try {
    return FEELFnResult.ofResult(LocalDate.from(FEEL_DATE.parse(val)));
  } catch (DateTimeException e) {
    // try to parse it as a date time and extract the date component
    // NOTE: this is an extension to the standard
    return BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(val)
        .cata(overrideLeft -> FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "date-parsing exception", e)),
            this::invoke
        );
  }
}
origin: org.kie/kie-dmn-feel

public FEELFnResult<TemporalAccessor> invoke(@ParameterName( "year" ) Number year, @ParameterName( "month" ) Number month, @ParameterName( "day" ) Number day,
                       @ParameterName( "hour" ) Number hour, @ParameterName( "minute" ) Number minute, @ParameterName( "second" ) Number second ) {
  return invoke( year, month, day, hour, minute, second, (Number) null );
}
origin: org.kie/kie-dmn-feel

@Test
public void testComposite4() {
  final FEELFnResult<TemporalAccessor> p1 = dateFunction.invoke("2017-01-01");
  final FEELFnResult<TemporalAccessor> p2 = timeFunction.invoke("23:59:01@Europe/Paris");
  FunctionTestUtil.assertResult(p1, LocalDate.of(2017, 1, 1));
  final TemporalAccessor p2TA = p2.getOrElse(null);
  assertNotNull(p2TA);
  assertEquals(LocalTime.of(23, 59, 1), p2TA.query(TemporalQueries.localTime()));
  assertEquals(ZoneId.of("Europe/Paris"), p2TA.query(TemporalQueries.zone()));
  final FEELFnResult<TemporalAccessor> result = dateTimeFunction.invoke(p1.getOrElse(null), p2.getOrElse(null));
  FunctionTestUtil.assertResult(result, ZonedDateTime.of(2017, 1, 1, 23, 59, 1, 0, ZoneId.of("Europe/Paris")));
}
origin: org.kie/kie-dmn-feel

  @Test
  public void testComposite5() {
    final FEELFnResult<TemporalAccessor> p1 = dateTimeFunction.invoke("2017-08-10T10:20:00@Europe/Paris");
    FunctionTestUtil.assertResult(p1, ZonedDateTime.of(2017, 8, 10, 10, 20, 0, 0, ZoneId.of("Europe/Paris")));

    final TemporalAccessor timeOnDateTime = timeFunction.invoke(p1.getOrElse(null)).getOrElse(null);
    assertNotNull(timeOnDateTime);
    assertEquals(LocalTime.of(10, 20, 0), timeOnDateTime.query(TemporalQueries.localTime()));
    assertEquals(ZoneId.of("Europe/Paris"), timeOnDateTime.query(TemporalQueries.zone()));

    FunctionTestUtil.assertResult(stringFunction.invoke(timeOnDateTime), "10:20:00@Europe/Paris");
  }
}
origin: org.kie/kie-dmn-feel

public FEELFnResult<TemporalAccessor> invoke(@ParameterName("from") String val) {
  if (val == null) {
    return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "cannot be null"));
  }
  try {
    TemporalAccessor parsed = FEEL_TIME.parse(val);
    if (parsed.query(TemporalQueries.offset()) != null) {
      // it is an offset-zoned time, so I can know for certain an OffsetTime
      OffsetTime asOffSetTime = parsed.query(OffsetTime::from);
      return FEELFnResult.ofResult(asOffSetTime);
    } else if (parsed.query(TemporalQueries.zone()) == null) {
      // if it does not contain any zone information at all, then I know for certain is a local time.
      LocalTime asLocalTime = parsed.query(LocalTime::from);
      return FEELFnResult.ofResult(asLocalTime);
    }
    return FEELFnResult.ofResult(parsed);
  } catch (DateTimeException e) {
    // try to parse it as a date time and extract the date component
    // NOTE: this is an extension to the standard
    return BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(val)
        .cata(overrideLeft -> FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "time-parsing exception", e)),
            this::invoke
        );
  }
}
origin: org.kie/kie-dmn-feel

public FEELFnResult<TemporalAccessor> invoke(@ParameterName("from") TemporalAccessor date) {
  if ( date == null ) {
    return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", "cannot be null"));
  }
  
  try {
    // If the temporal accessor type doesn't support time, try to parse it as a date with UTC midnight.
    if (!date.isSupported(ChronoField.HOUR_OF_DAY)) {
      return BuiltInFunctions.getFunction( DateAndTimeFunction.class ).invoke( date, OffsetTime.of(0, 0, 0, 0, ZoneOffset.UTC) )
          .cata( overrideLeft -> FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "time-parsing exception")),
              this::invoke
          );
    } else if( date.query( TemporalQueries.offset() ) == null ) {
      return FEELFnResult.ofResult( LocalTime.from( date ) );
    } else {
      ZoneId zone = date.query(TemporalQueries.zoneId());
      if (!(zone instanceof ZoneOffset)) {
        // TZ is a ZoneRegion, so do NOT normalize (although the result will be unreversible, but will keep what was supplied originally).
        // Unfortunately java.time.Parsed is a package-private class, hence will need to re-parse in order to have it instantiated. 
        return invoke(date.query(TemporalQueries.localTime()) + "@" + zone);
      } else {
        return FEELFnResult.ofResult(OffsetTime.from(date));
      }
    }
  } catch (DateTimeException e) {
    return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", "time-parsing exception", e));
  }
}
origin: org.kie/kie-dmn-feel

  public FEELFnResult<TemporalAccessor> invoke(@ParameterName("from") TemporalAccessor date) {
    if (date == null) {
      return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "cannot be null"));
    }

    try {
      // If the temporal accessor type doesn't support time, try to parse it as a date with UTC midnight.
      if (!date.isSupported(ChronoField.HOUR_OF_DAY)) {
        return BuiltInFunctions.getFunction( DateAndTimeFunction.class ).invoke( date, OffsetTime.of(0, 0, 0, 0, ZoneOffset.UTC) )
            .cata( overrideLeft -> FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "time-parsing exception")),
                this::invoke
            );
      } else if( date.query( TemporalQueries.offset() ) == null ) {
        return FEELFnResult.ofResult(LocalTime.from(date));
      } else {
        ZoneId zone = date.query(TemporalQueries.zoneId());
        if (!(zone instanceof ZoneOffset)) {
          // TZ is a ZoneRegion, so do NOT normalize (although the result will be unreversible, but will keep what was supplied originally).
          // Unfortunately java.time.Parsed is a package-private class, hence will need to re-parse in order to have it instantiated.
          return invoke(date.query(TemporalQueries.localTime()) + "@" + zone);
        } else {
          return FEELFnResult.ofResult(OffsetTime.from(date));
        }
      }
    } catch (DateTimeException e) {
      return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "from", "time-parsing exception", e));
    }
  }
}
org.kie.dmn.feel.runtime.functionsDateAndTimeFunction

Most used methods

  • invoke
  • <init>

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getContentResolver (Context)
  • findViewById (Activity)
  • getApplicationContext (Context)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • Socket (java.net)
    Provides a client-side TCP socket.
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • ArrayList (java.util)
    ArrayList is an implementation of List, backed by an array. All optional operations including adding
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now