]> source.dussan.org Git - poi.git/commitdiff
fix year agnostic date/test values
authorAndreas Beeker <kiwiwings@apache.org>
Fri, 1 Jan 2021 23:20:02 +0000 (23:20 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Fri, 1 Jan 2021 23:20:02 +0000 (23:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1885021 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/ss/formula/functions/TestDateValue.java

index 05da127bd92ace9e7bf6a6de9dd6cde24d46ed4b..055e9976502ad95a4b6155856e5412e97886066c 100644 (file)
@@ -19,6 +19,10 @@ package org.apache.poi.ss.formula.functions;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+import java.time.LocalDate;
+import java.time.Month;
+import java.time.Year;
+import java.time.temporal.ChronoUnit;
 import java.util.Locale;
 
 import org.apache.poi.ss.formula.eval.BlankEval;
@@ -52,14 +56,18 @@ public final class TestDateValue {
     public void testDateValue() {
         LocaleUtil.setUserLocale(Locale.ENGLISH);
         try {
+            int days1900 = (int)ChronoUnit.DAYS.between(
+                LocalDate.of(1899, Month.DECEMBER, 31),
+                LocalDate.of(Year.now().getValue(), Month.FEBRUARY, 1)
+            )+1;
             confirmDateValue(new StringEval("2020-02-01"), 43862);
             confirmDateValue(new StringEval("01-02-2020"), 43862);
             confirmDateValue(new StringEval("2020-FEB-01"), 43862);
             confirmDateValue(new StringEval("2020-Feb-01"), 43862);
             confirmDateValue(new StringEval("2020-FEBRUARY-01"), 43862);
-            confirmDateValue(new StringEval("FEB-01"), 43862);
+            confirmDateValue(new StringEval("FEB-01"), days1900);
             confirmDateValue(new StringEval("2/1/2020"), 43862);
-            confirmDateValue(new StringEval("2/1"), 43862);
+            confirmDateValue(new StringEval("2/1"), days1900);
             confirmDateValue(new StringEval("2020/2/1"), 43862);
             confirmDateValue(new StringEval("2020/FEB/1"), 43862);
             confirmDateValue(new StringEval("FEB/1/2020"), 43862);