View | Details | Raw Unified | Return to bug 43199
Collapse All | Expand All

(-)C:/data/Workspaces/wsp_poiSVN/trunc/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Year.java (-2 / +45 lines)
Lines 20-25 Link Here
20
 */
20
 */
21
package org.apache.poi.hssf.record.formula.functions;
21
package org.apache.poi.hssf.record.formula.functions;
22
22
23
public class Year extends NotImplementedFunction {
23
import org.apache.poi.hssf.record.formula.eval.BlankEval;
24
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
25
import org.apache.poi.hssf.record.formula.eval.Eval;
26
import org.apache.poi.hssf.record.formula.eval.NumberEval;
27
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
28
import org.apache.poi.hssf.record.formula.eval.ValueEval;
29
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
24
30
25
}
31
/**
32
 * 
33
 * @author Guenter Kickinger g.kickinger@gmx.net
34
 *
35
 */
36
37
public class Year extends NumericFunction {
38
39
	/* (non-Javadoc)
40
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[], int, short)
41
	 */
42
	public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
43
        ValueEval retval = null;
44
45
        switch (operands.length) {
46
        default:
47
            retval = ErrorEval.VALUE_INVALID;
48
            break;
49
        case 1:
50
            ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
51
            if (ve instanceof NumericValueEval) {
52
                NumericValueEval ne = (NumericValueEval) ve;
53
                if (HSSFDateUtil.isValidExcelDate(ne.getNumberValue())) {
54
                    java.util.Date d = HSSFDateUtil.getJavaDate(ne.getNumberValue());
55
                    retval = new NumberEval(d.getYear()+1900);
56
                } else {
57
                    retval = ErrorEval.NUM_ERROR;
58
                }
59
            }
60
            else if (ve instanceof BlankEval) {
61
                // do nothing
62
            } else {
63
                retval = ErrorEval.NUM_ERROR;
64
            }
65
        }
66
        return retval;
67
    }
68
}
(-)C:/data/Workspaces/wsp_poiSVN/trunc/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Month.java (-1 / +43 lines)
Lines 20-25 Link Here
20
 */
20
 */
21
package org.apache.poi.hssf.record.formula.functions;
21
package org.apache.poi.hssf.record.formula.functions;
22
22
23
public class Month extends NotImplementedFunction {
23
import org.apache.poi.hssf.record.formula.eval.BlankEval;
24
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
25
import org.apache.poi.hssf.record.formula.eval.Eval;
26
import org.apache.poi.hssf.record.formula.eval.NumberEval;
27
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
28
import org.apache.poi.hssf.record.formula.eval.ValueEval;
29
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
24
30
31
/**
32
 * 
33
 * @author Guenter Kickinger g.kickinger@gmx.net
34
 *
35
 */
36
public class Month extends NumericFunction {
37
38
	/* (non-Javadoc)
39
	 * @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[], int, short)
40
	 */
41
	public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
42
        ValueEval retval = null;
43
44
        switch (operands.length) {
45
        default:
46
            retval = ErrorEval.VALUE_INVALID;
47
            break;
48
        case 1:
49
            ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
50
            if (ve instanceof NumericValueEval) {
51
                NumericValueEval ne = (NumericValueEval) ve;
52
                if (HSSFDateUtil.isValidExcelDate(ne.getNumberValue())) {
53
                    java.util.Date d = HSSFDateUtil.getJavaDate(ne.getNumberValue());
54
                    retval = new NumberEval(d.getMonth()+1);
55
                } else {
56
                    retval = ErrorEval.NUM_ERROR;
57
                }
58
            }
59
            else if (ve instanceof BlankEval) {
60
                // do nothing
61
            } else {
62
                retval = ErrorEval.NUM_ERROR;
63
            }
64
        }
65
        return retval;
66
    }
25
}
67
}

Return to bug 43199