summaryrefslogtreecommitdiff
path: root/formula
diff options
context:
space:
mode:
authorWinfried Donkers <winfrieddonkers@libreoffice.org>2015-09-22 10:40:25 +0200
committerEike Rathke <erack@redhat.com>2015-10-06 21:21:16 +0000
commitf830600ece806ec365a4839e79afabe183c5e36d (patch)
tree1bcfeccf135fc1489b1f850ca3462df514f5b294 /formula
parente3ddcbea3fd8b9402ce2339de47793c4bc2b4b80 (diff)
tdf#50950 Add ODFF1.2 Calc function ISOWEEKNUM,
make Calc function WEEKNUM compliant with ODFF1.2, provide backward compatibility for Calc function WEEKNUM, add unit tests for ISOWEEKNUM, WEEKNUM and backward compatibility. Change-Id: I63af5543cea2f470d710462e55404ac754022c89 Reviewed-on: https://gerrit.libreoffice.org/18760 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'formula')
-rw-r--r--formula/source/core/api/FormulaCompiler.cxx71
-rw-r--r--formula/source/core/resource/core_resource.src9
2 files changed, 65 insertions, 15 deletions
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 4ee0f7268d82..9d613e992524 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -1247,23 +1247,66 @@ void FormulaCompiler::Factor()
else if( eOp == ocNot || eOp == ocNeg
|| (SC_OPCODE_START_1_PAR <= eOp && eOp < SC_OPCODE_STOP_1_PAR) )
{
- pFacToken = mpToken;
- eOp = NextToken();
- if( nNumFmt == css::util::NumberFormat::UNDEFINED && eOp == ocNot )
- nNumFmt = css::util::NumberFormat::LOGICAL;
- if (eOp == ocOpen)
+ if (eOp == ocIsoWeeknum && FormulaGrammar::isODFF( meGrammar ))
{
- NextToken();
- eOp = Expression();
+ // tdf#50950 ocIsoWeeknum can have 2 arguments when saved by older versions of Calc;
+ // the opcode then has to be changed to ocWeek for backward compatibilty
+ pFacToken = mpToken;
+ eOp = NextToken();
+ bool bNoParam = false;
+ if (eOp == ocOpen)
+ {
+ eOp = NextToken();
+ if (eOp == ocClose)
+ bNoParam = true;
+ else
+ eOp = Expression();
+ }
+ else
+ SetError( errPairExpected);
+ sal_uInt8 nSepCount = 0;
+ if( !bNoParam )
+ {
+ nSepCount++;
+ while ((eOp == ocSep) && (!pArr->GetCodeError() || !mbStopOnError))
+ {
+ nSepCount++;
+ NextToken();
+ eOp = Expression();
+ }
+ }
+ if (eOp != ocClose)
+ SetError( errPairExpected);
+ else
+ eOp = NextToken();
+ pFacToken->SetByte( nSepCount );
+ if (nSepCount == 2)
+ {
+ pFacToken->NewOpCode( ocWeek, FormulaToken::PrivateAccess());
+ }
+ PutCode( pFacToken );
}
else
- SetError( errPairExpected);
- if (eOp != ocClose)
- SetError( errPairExpected);
- else if ( !pArr->GetCodeError() )
- pFacToken->SetByte( 1 );
- PutCode( pFacToken );
- eOp = NextToken();
+ {
+ // standard handling of ocNot, ocNeg and 1-parameter opcodes
+ pFacToken = mpToken;
+ eOp = NextToken();
+ if( nNumFmt == css::util::NumberFormat::UNDEFINED && eOp == ocNot )
+ nNumFmt = css::util::NumberFormat::LOGICAL;
+ if (eOp == ocOpen)
+ {
+ NextToken();
+ eOp = Expression();
+ }
+ else
+ SetError( errPairExpected);
+ if (eOp != ocClose)
+ SetError( errPairExpected);
+ else if ( !pArr->GetCodeError() )
+ pFacToken->SetByte( 1 );
+ PutCode( pFacToken );
+ eOp = NextToken();
+ }
}
else if ((SC_OPCODE_START_2_PAR <= eOp && eOp < SC_OPCODE_STOP_2_PAR)
|| eOp == ocExternal
diff --git a/formula/source/core/resource/core_resource.src b/formula/source/core/resource/core_resource.src
index ed0aeca4522f..90cd6e5266c3 100644
--- a/formula/source/core/resource/core_resource.src
+++ b/formula/source/core/resource/core_resource.src
@@ -389,7 +389,8 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF
String SC_OPCODE_BETA_INV { Text = "BETAINV" ; };
String SC_OPCODE_BETA_DIST_MS { Text = "COM.MICROSOFT.BETA.DIST" ; };
String SC_OPCODE_BETA_INV_MS { Text = "COM.MICROSOFT.BETA.INV" ; };
- String SC_OPCODE_WEEK { Text = "ISOWEEKNUM" ; };
+ String SC_OPCODE_WEEK { Text = "WEEKNUM" ; };
+ String SC_OPCODE_ISOWEEKNUM { Text = "ISOWEEKNUM" ; };
String SC_OPCODE_EASTERSUNDAY { Text = "ORG.OPENOFFICE.EASTERSUNDAY" ; };
String SC_OPCODE_GET_DAY_OF_WEEK { Text = "WEEKDAY" ; };
String SC_OPCODE_NETWORKDAYS { Text = "NETWORKDAYS" ; };
@@ -811,6 +812,7 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_OOXML
String SC_OPCODE_BETA_DIST_MS { Text = "_xlfn.BETA.DIST" ; };
String SC_OPCODE_BETA_INV_MS { Text = "_xlfn.BETA.INV" ; };
String SC_OPCODE_WEEK { Text = "WEEKNUM" ; };
+ String SC_OPCODE_ISOWEEKNUM { Text = "_xlfn.ISOWEEKNUM" ; };
String SC_OPCODE_EASTERSUNDAY { Text = "EASTERSUNDAY" ; };
String SC_OPCODE_GET_DAY_OF_WEEK { Text = "WEEKDAY" ; };
String SC_OPCODE_NETWORKDAYS { Text = "NETWORKDAYS" ; };
@@ -1234,6 +1236,7 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH
String SC_OPCODE_BETA_DIST_MS { Text = "BETA.DIST" ; };
String SC_OPCODE_BETA_INV_MS { Text = "BETA.INV" ; };
String SC_OPCODE_WEEK { Text = "WEEKNUM" ; };
+ String SC_OPCODE_ISOWEEKNUM { Text = "ISOWEEKNUM" ; };
String SC_OPCODE_EASTERSUNDAY { Text = "EASTERSUNDAY" ; };
String SC_OPCODE_GET_DAY_OF_WEEK { Text = "WEEKDAY" ; };
String SC_OPCODE_NETWORKDAYS { Text = "NETWORKDAYS" ; };
@@ -2698,6 +2701,10 @@ Resource RID_STRLIST_FUNCTION_NAMES
{
Text [ en-US ] = "WEEKNUM" ;
};
+ String SC_OPCODE_ISOWEEKNUM
+ {
+ Text [ en-US ] = "ISOWEEKNUM" ;
+ };
String SC_OPCODE_EASTERSUNDAY
{
Text [ en-US ] = "EASTERSUNDAY" ;