aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2016-10-15 06:54:20 +0000
committerDominik Stadler <centic@apache.org>2016-10-15 06:54:20 +0000
commit2ae9b30a6cf3edd4c686ca3cc80cb13002683dba (patch)
tree8e12fc163d5352326ceda2793d0a3b367e67c4b3 /src/java
parent1bda7f6ef6a8bf05c311eeb9b9dc9619c046ca95 (diff)
downloadpoi-2ae9b30a6cf3edd4c686ca3cc80cb13002683dba.tar.gz
poi-2ae9b30a6cf3edd4c686ca3cc80cb13002683dba.zip
Bug 60029: apply suggested fix and fix some IntelliJ warnings
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765018 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/poi/ss/formula/functions/Days360.java43
1 files changed, 18 insertions, 25 deletions
diff --git a/src/java/org/apache/poi/ss/formula/functions/Days360.java b/src/java/org/apache/poi/ss/formula/functions/Days360.java
index 8dba976563..087e16b42b 100644
--- a/src/java/org/apache/poi/ss/formula/functions/Days360.java
+++ b/src/java/org/apache/poi/ss/formula/functions/Days360.java
@@ -67,38 +67,33 @@ import org.apache.poi.util.LocaleUtil;
*/
public class Days360 extends Var2or3ArgFunction {
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
- double result;
try {
double d0 = NumericFunction.singleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
double d1 = NumericFunction.singleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
- result = evaluate(d0, d1, false);
+ return new NumberEval(evaluate(d0, d1, false));
} catch (EvaluationException e) {
return e.getErrorEval();
}
- return new NumberEval(result);
}
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1,
ValueEval arg2) {
- double result;
try {
double d0 = NumericFunction.singleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
double d1 = NumericFunction.singleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
ValueEval ve = OperandResolver.getSingleValue(arg2, srcRowIndex, srcColumnIndex);
Boolean method = OperandResolver.coerceValueToBoolean(ve, false);
- result = evaluate(d0, d1, method == null ? false : method.booleanValue());
+ return new NumberEval(evaluate(d0, d1, method != null && method.booleanValue()));
} catch (EvaluationException e) {
return e.getErrorEval();
}
- return new NumberEval(result);
}
private static double evaluate(double d0, double d1, boolean method) {
Calendar realStart = getDate(d0);
Calendar realEnd = getDate(d1);
int startingDate[] = getStartingDate(realStart, method);
- int endingDate[] = getEndingDate(realEnd, realStart, method);
-
+ int endingDate[] = getEndingDate(realEnd, startingDate, method);
return
(endingDate[0]*360+endingDate[1]*30+endingDate[2])-
(startingDate[0]*360+startingDate[1]*30+startingDate[2]);
@@ -111,34 +106,32 @@ public class Days360 extends Var2or3ArgFunction {
}
private static int[] getStartingDate(Calendar realStart, boolean method) {
- Calendar d = realStart;
- int yyyy = d.get(Calendar.YEAR);
- int mm = d.get(Calendar.MONTH);
- int dd = Math.min(30, d.get(Calendar.DAY_OF_MONTH));
+ int yyyy = realStart.get(Calendar.YEAR);
+ int mm = realStart.get(Calendar.MONTH);
+ int dd = Math.min(30, realStart.get(Calendar.DAY_OF_MONTH));
- if (method == false && isLastDayOfMonth(d)) dd = 30;
+ if (!method && isLastDayOfMonth(realStart)) dd = 30;
return new int[]{yyyy,mm,dd};
}
- private static int[] getEndingDate(Calendar realEnd, Calendar realStart, boolean method) {
- Calendar d = realEnd;
- int yyyy = d.get(Calendar.YEAR);
- int mm = d.get(Calendar.MONTH);
- int dd = Math.min(30, d.get(Calendar.DAY_OF_MONTH));
+ private static int[] getEndingDate(Calendar realEnd, int startingDate[], boolean method) {
+ int yyyy = realEnd.get(Calendar.YEAR);
+ int mm = realEnd.get(Calendar.MONTH);
+ int dd = Math.min(30, realEnd.get(Calendar.DAY_OF_MONTH));
- if (method == false && realEnd.get(Calendar.DAY_OF_MONTH) == 31) {
- if (realStart.get(Calendar.DAY_OF_MONTH) < 30) {
- d.set(Calendar.DAY_OF_MONTH, 1);
- d.add(Calendar.MONTH, 1);
- yyyy = d.get(Calendar.YEAR);
- mm = d.get(Calendar.MONTH);
+ if (!method && realEnd.get(Calendar.DAY_OF_MONTH) == 31) {
+ if (startingDate[2] < 30) {
+ realEnd.set(Calendar.DAY_OF_MONTH, 1);
+ realEnd.add(Calendar.MONTH, 1);
+ yyyy = realEnd.get(Calendar.YEAR);
+ mm = realEnd.get(Calendar.MONTH);
dd = 1;
} else {
dd = 30;
}
}
-
+
return new int[]{yyyy,mm,dd};
}