nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: wangguanquan/eec
Pull request #347 (2023-03-27 10:24:46)

#346 修复 Excel 解析 1970 年前日期校验逻辑


Patch:
diff --git a/src/main/java/org/ttzero/excel/util/DateUtil.java b/src/main/java/org/ttzero/excel/util/DateUtil.java
index a5c2159c..06256e5b 100644
--- a/src/main/java/org/ttzero/excel/util/DateUtil.java
+++ b/src/main/java/org/ttzero/excel/util/DateUtil.java
@@ -249,9 +249,6 @@ public class DateUtil {
 
 
     public static LocalDateTime toLocalDateTime(double d) {
-        if (d < DAYS_1900_TO_1970) {
-            throw new UncheckedTypeException("ConstantNumber " + d + " can't convert to java.util.Date");
-        }
         int n = (int) d, m = (int) (((d - n) * MILLIS_OF_DAY + 0.5) / 1000); // Causes data over 0.5s to be carried over to 1s
         return LocalDateTime.ofInstant(Instant.ofEpochSecond((n - DAYS_1900_TO_1970) * 86400L + m).minusMillis(tz), ZoneId.systemDefault());
     }
@@ -264,9 +261,6 @@ public class DateUtil {
     }
 
     public static LocalDate toLocalDate(int n) {
-        if (n < DAYS_1900_TO_1970) {
-            throw new UncheckedTypeException("ConstantNumber " + n + " can't convert to java.util.Date");
-        }
         return LocalDate.ofEpochDay(n - DAYS_1900_TO_1970);
     }
 


Test patch:
diff --git a/src/test/java/org/ttzero/excel/util/DateUtilTest.java b/src/test/java/org/ttzero/excel/util/DateUtilTest.java
new file mode 100644
index 00000000..b88567cc
--- /dev/null
+++ b/src/test/java/org/ttzero/excel/util/DateUtilTest.java
@@ -0,0 +1,38 @@
+package org.ttzero.excel.util;
+
+import org.junit.Test;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+
+import static java.time.ZoneOffset.UTC;
+import static org.junit.Assert.*;
+import static org.ttzero.excel.util.DateUtil.DAYS_1900_TO_1970;
+
+/**
+ *
+ *
+ * @author CarlJia
+ * @date 2023-03-27
+ */
+public class DateUtilTest {
+
+    @Test
+    public void toLocalDate() {
+        LocalDate localDate = DateUtil.toLocalDate(24014);
+        LocalDate expectedLocalDate = LocalDate.of(1965, 9, 29);
+        assertEquals(expectedLocalDate, localDate);
+
+        LocalDate localDate1 = DateUtil.toLocalDate(-25567 + DAYS_1900_TO_1970);
+        LocalDate expectedLocalDate1 = LocalDate.of(1900, 1, 1);
+        assertEquals(expectedLocalDate1, localDate1);
+    }
+
+    @Test
+    public void toLocalDateTime() {
+        LocalDateTime localDateTime = DateUtil.toLocalDateTime(24014);
+        LocalDateTime expectedLocalDateTime = LocalDateTime.of(1965, 9, 29, 0, 0, 0);
+        assertEquals(expectedLocalDateTime, localDateTime);
+    }
+}
\ No newline at end of file