Kamilkime commented on code in PR #11283:
URL: https://github.com/apache/nifi/pull/11283#discussion_r3303458287


##########
nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/field/ObjectTimestampFieldConverterTest.java:
##########
@@ -162,6 +162,22 @@ public void 
testConvertFieldStringFormatCustomZoneOffsetCoordinatedUniversalTime
         assertEquals(expected, timestamp);
     }
 
+    @Test
+    public void testConvertFieldStringYearOneIsProlepticGregorian() {
+        final String yearOne = "0001-01-01 12:00:00";
+        final Timestamp timestamp = CONVERTER.convertField(yearOne, 
DEFAULT_PATTERN, FIELD_NAME);
+        final Instant expected = LocalDateTime.of(1, 1, 1, 12, 0, 
0).atZone(ZoneId.systemDefault()).toInstant();
+        assertEquals(expected, timestamp.toInstant());

Review Comment:
   Changed to Timestamp assertions



##########
nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/field/TestObjectLocalDateTimeFieldConverter.java:
##########
@@ -100,4 +101,18 @@ public void testWithDateFormatMicrosecondPrecision() {
         final LocalDateTime result = 
converter.convertField(MICROS_TIMESTAMP_LONG, 
Optional.of("yyyy-MM-dd'T'HH:mm:ss.SSSSSS"), FIELD_NAME);
         assertEquals(LOCAL_DATE_TIME_MICROS_PRECISION, result);
     }
+
+    @Test
+    public void testConvertTimestampYearOneIsProlepticGregorian() {
+        final LocalDateTime yearOne = LocalDateTime.of(1, 1, 1, 12, 0, 0);
+        final Timestamp timestamp = 
Timestamp.from(yearOne.atZone(ZoneId.systemDefault()).toInstant());
+        final LocalDateTime result = converter.convertField(timestamp, 
Optional.empty(), FIELD_NAME);
+        assertEquals(yearOne, result);
+    }
+
+    @Test
+    public void testConvertStringYearOneIsProlepticGregorian() {
+        final LocalDateTime result = converter.convertField("0001-01-01 
12:00:00", Optional.of("yyyy-MM-dd HH:mm:ss"), FIELD_NAME);
+        assertEquals(LocalDateTime.of(1, 1, 1, 12, 0, 0), result);

Review Comment:
   Extracted expected variable



##########
nifi-extension-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/avro/AvroTypeUtil.java:
##########
@@ -1153,11 +1153,9 @@ private static Object normalizeValue(final Object value, 
final Schema avroSchema
                 final String logicalName = logicalType.getName();
                 if (LOGICAL_TYPE_DATE.equals(logicalName)) {
                     // date logical name means that the value is number of 
days since Jan 1, 1970
-                    // Handle both Integer (legacy) and LocalDate (newer Avro 
libraries)
-                    if (value instanceof LocalDate localDate) {
-                        return java.sql.Date.valueOf(localDate);
-                    }
-                    return java.sql.Date.valueOf(LocalDate.ofEpochDay((int) 
value));
+                    // Handle both Integer (legacy) and LocalDate (newer Avro 
libraries).
+                    final LocalDate localDate = (value instanceof LocalDate 
ld) ? ld : LocalDate.ofEpochDay((int) value);
+                    return new 
java.sql.Date(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli());

Review Comment:
   Used an if statement for the localDate value, and extracted zonedDate



##########
nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/field/ObjectLocalDateFieldConverterTest.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.serialization.record.field;
+
+import org.junit.jupiter.api.Test;
+
+import java.sql.Date;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class ObjectLocalDateFieldConverterTest {
+
+    private static final ObjectLocalDateFieldConverter CONVERTER = new 
ObjectLocalDateFieldConverter();
+    private static final String FIELD_NAME = LocalDate.class.getSimpleName();
+
+    @Test
+    void testConvertFieldNull() {
+        assertNull(CONVERTER.convertField(null, Optional.empty(), FIELD_NAME));
+    }
+
+    @Test
+    void testConvertFieldLocalDate() {
+        final LocalDate input = LocalDate.of(2025, 5, 25);
+        assertEquals(input, CONVERTER.convertField(input, Optional.empty(), 
FIELD_NAME));
+    }
+
+    @Test
+    void testConvertFieldSqlDateModernYear() {
+        final LocalDate localDate = LocalDate.of(2025, 5, 25);
+        final Date sqlDate = new 
Date(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli());

Review Comment:
   Extracted zonedDate



-- 
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]

Reply via email to