yuyu1025 commented on code in PR #1385:
URL: https://github.com/apache/commons-lang/pull/1385#discussion_r2094467934


##########
src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java:
##########
@@ -1285,6 +1291,107 @@ public void testToCalendarWithTimeZoneNull() {
         assertThrows(NullPointerException.class, () -> 
DateUtils.toCalendar(date1, null));
     }
 
+    @ParameterizedTest
+    @MethodSource("dateConversionProvider")
+    void testToLocalDateTimeWithDate(Date sqlDate, LocalDateTime expected) {
+        LocalDateTime result = DateUtils.toLocalDateTime(sqlDate);
+        assertNotNull(result);
+        assertEquals(expected, result);
+    }
+
+    private static Stream<Arguments> dateConversionProvider() {
+        return Stream.of(
+                Arguments.of(
+                        java.sql.Date.valueOf("2000-01-01"),
+                        LocalDateTime.of(2000, 1, 1, 0, 0, 0)
+                ),
+                Arguments.of(
+                        java.sql.Date.valueOf("1970-01-01"),
+                        LocalDateTime.of(1970, 1, 1, 0, 0, 0)
+                ),
+                Arguments.of(
+                        java.sql.Time.valueOf("12:30:45"),
+                        LocalDateTime.of(1970, 1, 1, 12, 30, 45)
+                ),
+                Arguments.of(
+                        java.sql.Time.valueOf("23:59:59"),
+                        LocalDateTime.of(1970, 1, 1, 23, 59, 59)
+                ),
+                Arguments.of(
+                        java.sql.Timestamp.valueOf("2000-01-01 
12:30:45.123456789"),
+                        LocalDateTime.of(2000, 1, 1, 12, 30, 45, 123_456_789)
+                ),
+                Arguments.of(
+                        java.sql.Timestamp.valueOf("2000-01-01 
12:30:45.987654321"),
+                        LocalDateTime.of(2000, 1, 1, 12, 30, 45, 987_654_321)
+                )
+        );
+    }
+
+    @ParameterizedTest
+    @MethodSource("dateWithTimeZoneProvider")
+    void testToLocalDateTimeWithDate(
+            Date date,
+            TimeZone timeZone,
+            LocalDateTime expected) {
+        LocalDateTime result ;
+        if (timeZone != null) {
+            result = DateUtils.toLocalDateTime(date, timeZone);
+        } else {
+            result = DateUtils.toLocalDateTime(date);
+        }
+        assertEquals(expected, result);
+    }
+
+    private static Stream<Arguments> dateWithTimeZoneProvider() {
+        return Stream.of(
+                Arguments.of(
+                        java.sql.Timestamp.valueOf("2000-01-01 12:30:45"),
+                        TimeZone.getTimeZone("America/New_York"),
+                        LocalDateTime.ofInstant(
+                                java.sql.Timestamp.valueOf("2000-01-01 
12:30:45").toInstant(),
+                                
TimeZone.getTimeZone("America/New_York").toZoneId()
+                        )
+                ),

Review Comment:
   > Could you add some test cases with `java.sql.Date`?
   
   OK, I'll add some now.



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