poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r569062 - in /poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions: Month.java Year.java
Date Thu, 23 Aug 2007 16:33:46 GMT
Author: nick
Date: Thu Aug 23 09:33:36 2007
New Revision: 569062

URL: http://svn.apache.org/viewvc?rev=569062&view=rev
Log:
Implementation of Month and Year functions, from Guenter Kickinger (bug #43199)

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Month.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Year.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Month.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Month.java?rev=569062&r1=569061&r2=569062&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Month.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Month.java Thu
Aug 23 09:33:36 2007
@@ -20,6 +20,48 @@
  */
 package org.apache.poi.hssf.record.formula.functions;
 
-public class Month extends NotImplementedFunction {
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
 
+/**
+ * 
+ * @author Guenter Kickinger g.kickinger@gmx.net
+ *
+ */
+public class Month extends NumericFunction {
+
+	/* (non-Javadoc)
+	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[],
int, short)
+	 */
+	public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+        ValueEval retval = null;
+
+        switch (operands.length) {
+        default:
+            retval = ErrorEval.VALUE_INVALID;
+            break;
+        case 1:
+            ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
+            if (ve instanceof NumericValueEval) {
+                NumericValueEval ne = (NumericValueEval) ve;
+                if (HSSFDateUtil.isValidExcelDate(ne.getNumberValue())) {
+                    java.util.Date d = HSSFDateUtil.getJavaDate(ne.getNumberValue());
+                    retval = new NumberEval(d.getMonth()+1);
+                } else {
+                    retval = ErrorEval.NUM_ERROR;
+                }
+            }
+            else if (ve instanceof BlankEval) {
+                // do nothing
+            } else {
+                retval = ErrorEval.NUM_ERROR;
+            }
+        }
+        return retval;
+    }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Year.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Year.java?rev=569062&r1=569061&r2=569062&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Year.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Year.java Thu
Aug 23 09:33:36 2007
@@ -20,6 +20,49 @@
  */
 package org.apache.poi.hssf.record.formula.functions;
 
-public class Year extends NotImplementedFunction {
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
 
-}
+/**
+ * 
+ * @author Guenter Kickinger g.kickinger@gmx.net
+ *
+ */
+
+public class Year extends NumericFunction {
+
+	/* (non-Javadoc)
+	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[],
int, short)
+	 */
+	public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
+        ValueEval retval = null;
+
+        switch (operands.length) {
+        default:
+            retval = ErrorEval.VALUE_INVALID;
+            break;
+        case 1:
+            ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
+            if (ve instanceof NumericValueEval) {
+                NumericValueEval ne = (NumericValueEval) ve;
+                if (HSSFDateUtil.isValidExcelDate(ne.getNumberValue())) {
+                    java.util.Date d = HSSFDateUtil.getJavaDate(ne.getNumberValue());
+                    retval = new NumberEval(d.getYear()+1900);
+                } else {
+                    retval = ErrorEval.NUM_ERROR;
+                }
+            }
+            else if (ve instanceof BlankEval) {
+                // do nothing
+            } else {
+                retval = ErrorEval.NUM_ERROR;
+            }
+        }
+        return retval;
+    }
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message