This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new e33d4340a5e NIFI-14572 Fixed Zone Offset handling in DateTimeAdapter 
(#11129)
e33d4340a5e is described below

commit e33d4340a5e1c6b0988d6b46bb31c9b734fe7fc2
Author: superdachuan <[email protected]>
AuthorDate: Wed Jul 29 22:37:13 2026 +0800

    NIFI-14572 Fixed Zone Offset handling in DateTimeAdapter (#11129)
    
    Co-authored-by: David Handermann <[email protected]>
    Signed-off-by: David Handermann <[email protected]>
---
 .../nifi/web/api/dto/util/DateTimeAdapter.java     |  4 +-
 .../nifi/web/api/dto/util/DateTimeAdapterTest.java | 59 ++++++++++++++++++++++
 2 files changed, 61 insertions(+), 2 deletions(-)

diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/util/DateTimeAdapter.java
 
b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/util/DateTimeAdapter.java
index 9ba1ff76033..c7ba3138a39 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/util/DateTimeAdapter.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/util/DateTimeAdapter.java
@@ -18,6 +18,7 @@ package org.apache.nifi.web.api.dto.util;
 
 import jakarta.xml.bind.annotation.adapters.XmlAdapter;
 
+import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
@@ -39,8 +40,7 @@ public class DateTimeAdapter extends XmlAdapter<String, Date> 
{
 
     @Override
     public Date unmarshal(String date) throws Exception {
-        final ZonedDateTime zonedDateTime = ZonedDateTime.parse(date, 
DATE_TIME_FORMATTER);
+        final ZonedDateTime zonedDateTime = LocalDateTime.parse(date, 
DATE_TIME_FORMATTER).atZone(ZoneId.systemDefault());
         return Date.from(zonedDateTime.toInstant());
     }
-
 }
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/util/DateTimeAdapterTest.java
 
b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/util/DateTimeAdapterTest.java
new file mode 100644
index 00000000000..41f7292fca0
--- /dev/null
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/util/DateTimeAdapterTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.apache.nifi.web.api.dto.util;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import java.util.Date;
+import java.util.TimeZone;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class DateTimeAdapterTest {
+
+    private static final long TEST_DATE_TIME_MILLISECONDS = 1767323096000L; // 
2026-01-02T03:04:56Z
+    private static final Date TEST_DATE = new 
Date(TEST_DATE_TIME_MILLISECONDS);
+
+    @ParameterizedTest
+    @CsvSource({
+            "UTC,                01/02/2026 03:04:56 UTC",
+            "Asia/Shanghai,      01/02/2026 11:04:56 CST",
+            "America/Chicago,    01/01/2026 21:04:56 CST",
+            "Asia/Kolkata,       01/02/2026 08:34:56 IST",
+            "America/St_Johns,   01/01/2026 23:34:56 NST",
+            "America/New_York,   01/01/2026 22:04:56 EST",
+            "Asia/Tokyo,         01/02/2026 12:04:56 JST",
+            "Australia/Adelaide, 01/02/2026 13:34:56 ACDT",
+            "Pacific/Auckland,   01/02/2026 16:04:56 NZDT",
+            "Europe/Berlin,      01/02/2026 04:04:56 CET"
+    })
+    void testMarshalAndUnmarshal(final String timeZoneId, final String 
expectedDateTime) throws Exception {
+        final TimeZone originalTimeZone = TimeZone.getDefault();
+        try {
+            TimeZone.setDefault(TimeZone.getTimeZone(timeZoneId));
+
+            final DateTimeAdapter dateTimeAdapter = new DateTimeAdapter();
+
+            assertEquals(expectedDateTime, dateTimeAdapter.marshal(TEST_DATE));
+
+            assertEquals(TEST_DATE, 
dateTimeAdapter.unmarshal(expectedDateTime));
+        } finally {
+            TimeZone.setDefault(originalTimeZone);
+        }
+    }
+}

Reply via email to