This is an automated email from the ASF dual-hosted git repository.
gitgabrio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-drools.git
The following commit(s) were added to refs/heads/main by this push:
new 8419e523df [incubator-kie-issues#1829] Fix zero-seconds truncation on
date time (#6255)
8419e523df is described below
commit 8419e523df90991062171df36f2c3b70ed3b6930
Author: Gabriele Cardosi <[email protected]>
AuthorDate: Mon Feb 17 10:07:29 2025 +0100
[incubator-kie-issues#1829] Fix zero-seconds truncation on date time (#6255)
Co-authored-by: Gabriele-Cardosi <[email protected]>
---
.../org/kie/dmn/feel/runtime/custom/ZoneTime.java | 11 +++--
.../dmn/feel/runtime/functions/TimeFunction.java | 12 ++++--
.../functions/ComposingDifferentFunctionsTest.java | 2 +-
.../runtime/functions/DateAndTimeFunctionTest.java | 48 ++++++++++++++++++++++
.../feel/runtime/functions/TimeFunctionTest.java | 34 ++++++++++++++-
5 files changed, 95 insertions(+), 12 deletions(-)
diff --git
a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/custom/ZoneTime.java
b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/custom/ZoneTime.java
index 8cdbb64d33..fe8954a5d8 100644
---
a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/custom/ZoneTime.java
+++
b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/custom/ZoneTime.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -107,7 +107,8 @@ public final class ZoneTime
this.offsetTime = OffsetTime.of(localTime, offset);
this.zoneId = zoneId;
this.hasSeconds = hasSeconds;
- this.stringRepresentation = String.format("%s@%s", localTime, zoneId);
+ String localTimeString =
localTime.format(DateTimeFormatter.ISO_LOCAL_TIME);
+ this.stringRepresentation = String.format("%s@%s", localTimeString,
zoneId);
}
// package default for testing purpose
@@ -146,14 +147,12 @@ public final class ZoneTime
@Override
public Temporal minus(long amountToSubtract, TemporalUnit unit) {
- return
- getNewZoneOffset(offsetTime.minus(amountToSubtract, unit));
+ return getNewZoneOffset(offsetTime.minus(amountToSubtract, unit));
}
@Override
public Temporal minus(TemporalAmount amount) {
- return
- getNewZoneOffset(offsetTime.minus(amount));
+ return getNewZoneOffset(offsetTime.minus(amount));
}
@Override
diff --git
a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java
b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java
index 4bd472e829..b5c6c39e20 100644
---
a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java
+++
b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/TimeFunction.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -68,7 +68,13 @@ public class TimeFunction
return timePattern.matcher(val).find();
}
- private static final BigDecimal NANO_MULT = BigDecimal.valueOf( 1000000000
);
+ static String
getFormattedStringFromTemporalAccessorAndZone(TemporalAccessor date, ZoneId
zone) {
+ LocalTime localTime = date.query(TemporalQueries.localTime());
+ String localTimeString =
localTime.format(DateTimeFormatter.ISO_LOCAL_TIME);
+ return String.format("%s@%s", localTimeString, zone);
+ }
+
+ private static final BigDecimal NANO_MULT = BigDecimal.valueOf(1000000000);
protected TimeFunction() {
@@ -161,7 +167,7 @@ public class TimeFunction
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);
+ return
invoke(getFormattedStringFromTemporalAccessorAndZone(date, zone));
} else {
return FEELFnResult.ofResult(OffsetTime.from(date));
}
diff --git
a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java
b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java
index 4914f64143..938a0f3cbc 100644
---
a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java
+++
b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ComposingDifferentFunctionsTest.java
@@ -92,6 +92,6 @@ class ComposingDifferentFunctionsTest {
assertThat(timeOnDateTime.query(TemporalQueries.localTime())).isEqualTo(LocalTime.of(10,
20, 0));
assertThat(timeOnDateTime.query(TemporalQueries.zone())).isEqualTo(ZoneId.of("Europe/Paris"));
- FunctionTestUtil.assertResult(stringFunction.invoke(timeOnDateTime),
"10:20@Europe/Paris");
+ FunctionTestUtil.assertResult(stringFunction.invoke(timeOnDateTime),
"10:20:00@Europe/Paris");
}
}
\ No newline at end of file
diff --git
a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunctionTest.java
b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunctionTest.java
new file mode 100644
index 0000000000..d271b324fa
--- /dev/null
+++
b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/DateAndTimeFunctionTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.runtime.functions;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.temporal.TemporalAccessor;
+import org.junit.jupiter.api.Test;
+
+class DateAndTimeFunctionTest {
+
+ private final DateAndTimeFunction dateTimeFunction =
DateAndTimeFunction.INSTANCE;
+
+ @Test
+ void invokeFromString() {
+ FEELFnResult<TemporalAccessor> retrievedResult =
dateTimeFunction.invoke("2017-08-10T10:20:00@Europe/Paris");
+ assertThat(retrievedResult).isNotNull();
+ assertThat(retrievedResult.isRight()).isTrue();
+ TemporalAccessor retrieved = retrievedResult.getOrElse(null);
+ assertThat(retrieved).isNotNull().isInstanceOf(ZonedDateTime.class);
+ ZonedDateTime retrievedZonedDateTime = (ZonedDateTime) retrieved;
+ assertThat(retrievedZonedDateTime.getYear()).isEqualTo(2017);
+ assertThat(retrievedZonedDateTime.getMonthValue()).isEqualTo(8);
+ assertThat(retrievedZonedDateTime.getDayOfMonth()).isEqualTo(10);
+ assertThat(retrievedZonedDateTime.getHour()).isEqualTo(10);
+ assertThat(retrievedZonedDateTime.getMinute()).isEqualTo(20);
+ assertThat(retrievedZonedDateTime.getSecond()).isZero();
+
assertThat(retrievedZonedDateTime.getZone()).isEqualTo(ZoneId.of("Europe/Paris"));
+ }
+}
diff --git
a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java
b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java
index d22769d419..c4985c8ccc 100644
---
a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java
+++
b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/TimeFunctionTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -27,10 +27,11 @@ import java.time.LocalTime;
import java.time.OffsetTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQueries;
-
import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.runtime.custom.ZoneTime;
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
import static org.assertj.core.api.Assertions.assertThat;
@@ -185,6 +186,20 @@ class TimeFunctionTest {
OffsetTime.of(10, 43, 15, 154000000, ZoneOffset.ofHours(-1)));
}
+ @Test
+ void invokeWithZonedDateTime() {
+ ZonedDateTime from = (ZonedDateTime)
DateAndTimeFunction.INSTANCE.invoke("2017-08-10T10:20:00@Europe/Paris")
+ .getOrElse(null);
+ assertThat(from).isNotNull();
+ FEELFnResult<TemporalAccessor> retrievedResult =
timeFunction.invoke(from);
+ assertThat(retrievedResult.isRight()).isTrue();
+ TemporalAccessor retrieved = retrievedResult.getOrElse(null);
+ assertThat(retrieved).isNotNull().isInstanceOf(ZoneTime.class);
+ ZoneTime retrievedZoneTime = (ZoneTime) retrieved;
+ assertThat(retrievedZoneTime).isNotNull();
+ assertThat(retrievedZoneTime).hasToString("10:20:00@Europe/Paris");
+ }
+
@Test
void timeStringWithSeconds() {
assertThat(TimeFunction.timeStringWithSeconds("10:10:00@Australia/Melbourne")).isTrue();
@@ -194,4 +209,19 @@ class TimeFunctionTest {
assertThat(TimeFunction.timeStringWithSeconds("10:10@Australia/Melbourne")).isFalse();
assertThat(TimeFunction.timeStringWithSeconds("10:10+10:00")).isFalse();
}
+
+ @Test
+ void getFormattedStringFromTemporalAccessorAndZone() {
+ ZonedDateTime date = (ZonedDateTime)
DateAndTimeFunction.INSTANCE.invoke("2017-08-10T10:20:10@Europe/Paris")
+ .getOrElse(null);
+ assertThat(date).isNotNull();
+ ZoneId zone = date.query(TemporalQueries.zoneId());
+
assertThat(TimeFunction.getFormattedStringFromTemporalAccessorAndZone(date,
zone))
+ .isEqualTo("10:20:10@Europe/Paris");
+ date = (ZonedDateTime)
DateAndTimeFunction.INSTANCE.invoke("2017-08-10T10:20:00@Europe/Paris").getOrElse(null);
+ assertThat(date).isNotNull();
+ zone = date.query(TemporalQueries.zoneId());
+
assertThat(TimeFunction.getFormattedStringFromTemporalAccessorAndZone(date,
zone))
+ .isEqualTo("10:20:00@Europe/Paris");
+ }
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]