ASF Bugzilla – Attachment 30414 Details for
Bug 55081
[PATCH] Function WEEKNUM is incomplete
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch for missing function WEEKNUM
WeekNum.patch (text/plain), 6.69 KB, created by
Cédric Walter
on 2013-06-08 16:28:07 UTC
(
hide
)
Description:
patch for missing function WEEKNUM
Filename:
MIME Type:
Creator:
Cédric Walter
Created:
2013-06-08 16:28:07 UTC
Size:
6.69 KB
patch
obsolete
>Index: poi/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- poi/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java (revision ) >+++ poi/src/testcases/org/apache/poi/ss/formula/functions/TestWeekNumFunctionsFromSpreadsheet.java (revision ) >@@ -0,0 +1,31 @@ >+/* ==================================================================== >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You under the Apache License, Version 2.0 >+ (the "License"); you may not use this file except in compliance with >+ the License. You may obtain a copy of the License at >+ >+ http://www.apache.org/licenses/LICENSE-2.0 >+ >+ Unless required by applicable law or agreed to in writing, software >+ distributed under the License is distributed on an "AS IS" BASIS, >+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ See the License for the specific language governing permissions and >+ limitations under the License. >+==================================================================== */ >+ >+package org.apache.poi.ss.formula.functions; >+ >+/** >+ * Tests WeekNum() as loaded from a test data spreadsheet.<p/> >+ * >+ * @author cedric dot walter @ gmail dot com >+ */ >+public class TestWeekNumFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet { >+ >+ @Override >+ protected String getFilename() { >+ return "WeekNumFunctionTestCaseData.xls"; >+ } >+} >\ No newline at end of file >Index: poi/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- poi/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java (revision 1490713) >+++ poi/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java (revision ) >@@ -158,7 +158,7 @@ > r(m, "TBILLEQ", null); > r(m, "TBILLPRICE", null); > r(m, "TBILLYIELD", null); >- r(m, "WEEKNUM", null); >+ r(m, "WEEKNUM", WeekNum.instance); > r(m, "WORKDAY", WorkdayFunction.instance); > r(m, "XIRR", null); > r(m, "XNPV", null); >Index: poi/src/java/org/apache/poi/ss/formula/functions/WeekNum.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- poi/src/java/org/apache/poi/ss/formula/functions/WeekNum.java (revision ) >+++ poi/src/java/org/apache/poi/ss/formula/functions/WeekNum.java (revision ) >@@ -0,0 +1,88 @@ >+/* ==================================================================== >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You under the Apache License, Version 2.0 >+ (the "License"); you may not use this file except in compliance with >+ the License. You may obtain a copy of the License at >+ >+ http://www.apache.org/licenses/LICENSE-2.0 >+ >+ Unless required by applicable law or agreed to in writing, software >+ distributed under the License is distributed on an "AS IS" BASIS, >+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ See the License for the specific language governing permissions and >+ limitations under the License. >+==================================================================== */ >+ >+package org.apache.poi.ss.formula.functions; >+ >+import org.apache.poi.ss.formula.OperationEvaluationContext; >+import org.apache.poi.ss.formula.eval.*; >+import org.apache.poi.ss.usermodel.DateUtil; >+ >+import java.util.Calendar; >+import java.util.GregorianCalendar; >+ >+/** >+ * Implementation for Excel WeekNum() function.<p/> >+ * <p/> >+ * <b>Syntax</b>:<br/> <b>WeekNum </b>(<b>Serial_num</b>,<b>Return_type</b>)<br/> >+ * <p/> >+ * Returns a number that indicates where the week falls numerically within a year. >+ * <p/> >+ * <p/> >+ * Serial_num is a date within the week. Dates should be entered by using the DATE function, >+ * or as results of other formulas or functions. For example, use DATE(2008,5,23) >+ * for the 23rd day of May, 2008. Problems can occur if dates are entered as text. >+ * Return_type is a number that determines on which day the week begins. The default is 1. >+ * 1 Week begins on Sunday. Weekdays are numbered 1 through 7. >+ * 2 Week begins on Monday. Weekdays are numbered 1 through 7. >+ * >+ * @author cedric dot walter @ gmail dot com >+ */ >+public class WeekNum extends Fixed2ArgFunction implements FreeRefFunction { >+ >+ public static final FreeRefFunction instance = new WeekNum(); >+ >+ public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval serialNumVE, ValueEval returnTypeVE) { >+ double serialNum = 0.0; >+ try { >+ serialNum = NumericFunction.singleOperandEvaluate(serialNumVE, srcRowIndex, srcColumnIndex); >+ } catch (EvaluationException e) { >+ return ErrorEval.VALUE_INVALID; >+ } >+ Calendar serialNumCalendar = new GregorianCalendar(); >+ serialNumCalendar.setTime(DateUtil.getJavaDate(serialNum, false)); >+ >+ int returnType = 0; >+ try { >+ ValueEval ve = OperandResolver.getSingleValue(returnTypeVE, srcRowIndex, srcColumnIndex); >+ returnType = OperandResolver.coerceValueToInt(ve); >+ } catch (EvaluationException e) { >+ return ErrorEval.NUM_ERROR; >+ } >+ >+ if (returnType != 1 && returnType != 2) { >+ return ErrorEval.NUM_ERROR; >+ } >+ >+ return new NumberEval(this.getWeekNo(serialNumCalendar, returnType)); >+ } >+ >+ public int getWeekNo(Calendar cal, int weekStartOn) { >+ if (weekStartOn == 1) { >+ cal.setFirstDayOfWeek(Calendar.SUNDAY); >+ } else { >+ cal.setFirstDayOfWeek(Calendar.MONDAY); >+ } >+ return cal.get(Calendar.WEEK_OF_YEAR); >+ } >+ >+ public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { >+ if (args.length == 2) { >+ return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]); >+ } >+ return ErrorEval.VALUE_INVALID; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 55081
:
30413
| 30414 |
30453
|
34776