aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2014-07-22 12:31:56 +0000
committerDominik Stadler <centic@apache.org>2014-07-22 12:31:56 +0000
commit3853004e6dba68f84888d5572744894b27ab6439 (patch)
tree913e639f3e9dd9c9213bf1b71596aaefd81543fb /src/java/org/apache/poi
parent5e74bf91336fcdd238ea31a85f5a047424d7678c (diff)
downloadpoi-3853004e6dba68f84888d5572744894b27ab6439.tar.gz
poi-3853004e6dba68f84888d5572744894b27ab6439.zip
Bug 56688: Fix border cases in EDATE function: handle RefEval and BlankEval and also return #VALUE, not #REF if case of error
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1612557 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r--src/java/org/apache/poi/ss/formula/functions/EDate.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/java/org/apache/poi/ss/formula/functions/EDate.java b/src/java/org/apache/poi/ss/formula/functions/EDate.java
index 22832690e3..75e5509940 100644
--- a/src/java/org/apache/poi/ss/formula/functions/EDate.java
+++ b/src/java/org/apache/poi/ss/formula/functions/EDate.java
@@ -36,8 +36,7 @@ public class EDate implements FreeRefFunction {
}
try {
double startDateAsNumber = getValue(args[0]);
- NumberEval offsetInYearsValue = (NumberEval) args[1];
- int offsetInMonthAsNumber = (int) offsetInYearsValue.getNumberValue();
+ int offsetInMonthAsNumber = (int) getValue(args[1]);
Date startDate = DateUtil.getJavaDate(startDateAsNumber);
Calendar calendar = Calendar.getInstance();
@@ -53,10 +52,18 @@ public class EDate implements FreeRefFunction {
if (arg instanceof NumberEval) {
return ((NumberEval) arg).getNumberValue();
}
+ if(arg instanceof BlankEval) {
+ return 0;
+ }
if (arg instanceof RefEval) {
ValueEval innerValueEval = ((RefEval) arg).getInnerValueEval();
- return ((NumberEval) innerValueEval).getNumberValue();
+ if(innerValueEval instanceof NumberEval) {
+ return ((NumberEval) innerValueEval).getNumberValue();
+ }
+ if(innerValueEval instanceof BlankEval) {
+ return 0;
+ }
}
- throw new EvaluationException(ErrorEval.REF_INVALID);
+ throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
}