gitgabrio commented on code in PR #6303:
URL:
https://github.com/apache/incubator-kie-drools/pull/6303#discussion_r2041605980
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunction.java:
##########
@@ -185,5 +201,30 @@ 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;
+ }
+ if (timeZone == null || timeZone.isEmpty() ||
TimeZone.getTimeZone(timeZone) == null) {
Review Comment:
Since you implemented the `FEELFnResult<TemporalAccessor>
validate*(TemporalAccessor)` logic, it would be worth to do the same for
`timeZone` itself (validateTimeZone(timeZone) should return a result containing
`ZoneId`, so its signature should be sligthly different then the others)
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateTimeFunctionTest.java:
##########
@@ -26,10 +26,13 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
+import java.time.temporal.TemporalAccessor;
import org.junit.jupiter.api.Test;
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
+import static org.assertj.core.api.Assertions.assertThat;
+
class DateTimeFunctionTest {
Review Comment:
For some reason, there are duplicated test classes for `DateAndTimeFunction`
could you please
1. move all the tests from `DateTimeFunctionTest` to
`DateAndTimeFunctionTest` ? (it follow the convention {tested_clas_name}Test)
2. delete `DateTimeFunctionTest`
Thanks! 🙏
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunction.java:
##########
@@ -58,6 +58,32 @@ public class DateAndTimeFunction
.toFormatter();
}
+ static FEELFnResult<TemporalAccessor> validateDate(TemporalAccessor date) {
Review Comment:
👍
##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunction.java:
##########
@@ -58,6 +58,32 @@ public class DateAndTimeFunction
.toFormatter();
}
+ static FEELFnResult<TemporalAccessor> validateDate(TemporalAccessor date) {
+ 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) )"));
+ }
+ }
+ return FEELFnResult.ofResult(date);
+ }
+
+ static FEELFnResult<TemporalAccessor> validateTime(TemporalAccessor time) {
Review Comment:
👍
--
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]