aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss/formula/eval
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2019-03-16 15:41:46 +0000
committerYegor Kozlov <yegor@apache.org>2019-03-16 15:41:46 +0000
commit6ef332b48eab1fe1e133e7617b587ad2048c1a03 (patch)
tree0fe8385f681819436cc6e1e6057128e0d9b57e8f /src/testcases/org/apache/poi/ss/formula/eval
parentee83ce5fcd19ae18713bfbcf9d6f508aff466eeb (diff)
downloadpoi-6ef332b48eab1fe1e133e7617b587ad2048c1a03.tar.gz
poi-6ef332b48eab1fe1e133e7617b587ad2048c1a03.zip
Bug 61472: Convert date/time strings to numbers when evaluating formulas
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1855662 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss/formula/eval')
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java b/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java
index 72fb29ca63..c329672265 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestOperandResolver.java
@@ -20,6 +20,9 @@ package org.apache.poi.ss.formula.eval;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
/**
* Tests for <tt>OperandResolver</tt>
*
@@ -74,4 +77,29 @@ public final class TestOperandResolver extends TestCase {
assertNull(OperandResolver.parseDouble(value));
}
}
+
+ public void testCoerceDateStringToNumber() throws EvaluationException {
+ Map<String, Double> values = new LinkedHashMap<>();
+ values.put("2019/1/18", 43483.);
+ values.put("01/18/2019", 43483.);
+ values.put("18 Jan 2019", 43483.);
+ values.put("18-Jan-2019", 43483.);
+
+ for (String str : values.keySet()) {
+ assertEquals(OperandResolver.coerceValueToDouble(new StringEval(str)), values.get(str), 0.00001);
+ }
+ }
+
+ public void testCoerceTimeStringToNumber() throws EvaluationException {
+ Map<String, Double> values = new LinkedHashMap<>();
+ values.put("00:00", 0.0);
+ values.put("12:00", 0.5);
+ values.put("15:43:09", 0.654965278);
+ values.put("15:43", 0.654861111);
+ values.put("3:43 PM", 0.654861111);
+
+ for (String str : values.keySet()) {
+ assertEquals(OperandResolver.coerceValueToDouble(new StringEval(str)), values.get(str), 0.00001);
+ }
+ }
}