gitgabrio commented on code in PR #6303:
URL:
https://github.com/apache/incubator-kie-drools/pull/6303#discussion_r2044406565
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunction.java:
##########
@@ -82,30 +119,20 @@ public FEELFnResult<TemporalAccessor>
invoke(@ParameterName( "from" ) String val
}
}
- public FEELFnResult<TemporalAccessor> invoke(@ParameterName( "date" )
TemporalAccessor date, @ParameterName( "time" ) TemporalAccessor time) {
- if ( date == null ) {
- return FEELFnResult.ofError(new
InvalidParametersEvent(Severity.ERROR, "date", "cannot be null"));
- }
- if ( !(date instanceof LocalDate) ) {
- // 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]
- // I try to convert `date` to a LocalDate, if the query method
returns null would signify conversion is not possible.
- date = date.query(TemporalQueries.localDate());
-
- if (date == null) {
- return FEELFnResult.ofError(new
InvalidParametersEvent(Severity.ERROR, "date", "must be an instance of
LocalDate (or must be possible to convert to a FEEL date using built-in
date(date) )"));
- }
+ public FEELFnResult<TemporalAccessor> invoke(@ParameterName("date")
TemporalAccessor date, @ParameterName("time") TemporalAccessor time) {
+ FEELFnResult<TemporalAccessor> dateValidationResult =
validateDate(date);
+ if (dateValidationResult.isLeft()) {
+ return dateValidationResult;
}
- if ( time == null ) {
- return FEELFnResult.ofError(new
InvalidParametersEvent(Severity.ERROR, "time", "cannot be null"));
- }
- if (!(time instanceof LocalTime ||
(time.query(TemporalQueries.localTime()) != null &&
time.query(TemporalQueries.zone()) != null))) {
- return FEELFnResult.ofError(new
InvalidParametersEvent(Severity.ERROR, "time", "must be an instance of
LocalTime or (it must contain localTime AND zone)"));
+ FEELFnResult<TemporalAccessor> timeValidationResult =
validateTime(time);
+ if (timeValidationResult.isLeft()) {
+ return timeValidationResult;
}
-
try {
- if( date instanceof LocalDate && time instanceof LocalTime ) {
- return FEELFnResult.ofResult( LocalDateTime.of( (LocalDate)
date, (LocalTime) time ) );
- } else if (date instanceof LocalDate &&
(time.query(TemporalQueries.localTime()) != null &&
time.query(TemporalQueries.zone()) != null)) {
+ date = dateValidationResult.getOrElse(null);
Review Comment:
Hi @AthiraHari77
Sorry, but that
`dateValidationResult.getOrElse(null)` reintroduce a potential bug that
should have been take care of by
`validateDate(date);`
1. the code correctly invoke `validateDate` , to check that it is not `null`
2. then, `dateValidationResult.getOrElse(null)` reintroduce the chance to
date being `null`
3. it does not happen becuase of previous `if
(dateValidationResult.isLeft())` invocation, but that
`dateValidationResult.getOrElse(null)` is wrong, by itself.
If `dateValidationResult` contains `null` and not a date, for whatever
reason, then an exception should be thrown.
Please replace `date = dateValidationResult.getOrElse(null);` with
`date = dateValidationResult.getOrElseThrow(_to_be_define);`
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunction.java:
##########
@@ -185,5 +212,31 @@ public FEELFnResult<TemporalAccessor>
invoke(@ParameterName( "year" ) Number yea
}
}
+ public FEELFnResult<TemporalAccessor> invoke(@ParameterName("date")
TemporalAccessor date, @ParameterName("time") TemporalAccessor time,
@ParameterName("timeZone") String timeZone) {
+ FEELFnResult<TemporalAccessor> dateValidationResult =
validateDate(date);
+ if (dateValidationResult.isLeft()) {
+ return dateValidationResult;
+ }
+ FEELFnResult<TemporalAccessor> timeValidationResult =
validateTime(time);
+ if (timeValidationResult.isLeft()) {
+ return timeValidationResult;
+ }
+ FEELFnResult<ZoneId> timeZoneValidationResult =
validateTimeZone(timeZone);
+ if (timeZoneValidationResult.isLeft()) {
+ return timeZoneValidationResult.cata(FEELFnResult::ofError, value
-> null);
+ }
+ try {
+ date = dateValidationResult.getOrElse(null);
Review Comment:
@AthiraHari77
See comments above
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunction.java:
##########
@@ -82,30 +119,20 @@ public FEELFnResult<TemporalAccessor>
invoke(@ParameterName( "from" ) String val
}
}
- public FEELFnResult<TemporalAccessor> invoke(@ParameterName( "date" )
TemporalAccessor date, @ParameterName( "time" ) TemporalAccessor time) {
- if ( date == null ) {
- return FEELFnResult.ofError(new
InvalidParametersEvent(Severity.ERROR, "date", "cannot be null"));
- }
- if ( !(date instanceof LocalDate) ) {
- // 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]
- // I try to convert `date` to a LocalDate, if the query method
returns null would signify conversion is not possible.
- date = date.query(TemporalQueries.localDate());
-
- if (date == null) {
- return FEELFnResult.ofError(new
InvalidParametersEvent(Severity.ERROR, "date", "must be an instance of
LocalDate (or must be possible to convert to a FEEL date using built-in
date(date) )"));
- }
+ public FEELFnResult<TemporalAccessor> invoke(@ParameterName("date")
TemporalAccessor date, @ParameterName("time") TemporalAccessor time) {
+ FEELFnResult<TemporalAccessor> dateValidationResult =
validateDate(date);
+ if (dateValidationResult.isLeft()) {
+ return dateValidationResult;
}
- if ( time == null ) {
- return FEELFnResult.ofError(new
InvalidParametersEvent(Severity.ERROR, "time", "cannot be null"));
- }
- if (!(time instanceof LocalTime ||
(time.query(TemporalQueries.localTime()) != null &&
time.query(TemporalQueries.zone()) != null))) {
- return FEELFnResult.ofError(new
InvalidParametersEvent(Severity.ERROR, "time", "must be an instance of
LocalTime or (it must contain localTime AND zone)"));
+ FEELFnResult<TemporalAccessor> timeValidationResult =
validateTime(time);
+ if (timeValidationResult.isLeft()) {
+ return timeValidationResult;
}
-
try {
- if( date instanceof LocalDate && time instanceof LocalTime ) {
- return FEELFnResult.ofResult( LocalDateTime.of( (LocalDate)
date, (LocalTime) time ) );
- } else if (date instanceof LocalDate &&
(time.query(TemporalQueries.localTime()) != null &&
time.query(TemporalQueries.zone()) != null)) {
+ date = dateValidationResult.getOrElse(null);
+ if (date instanceof LocalDate && time instanceof LocalTime) {
+ return FEELFnResult.ofResult( LocalDateTime.of( (LocalDate)
date, (LocalTime) time ));
Review Comment:
Here, IINW, time it is still the original parameter, while `date` is the one
retrieved from `dateValidationResult`:
please use a consistent way to manage equivalent variables
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]