[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - formula/source include/formula sc/inc sc/qa sc/source

Eike Rathke erack at redhat.com
Tue Jan 5 11:56:30 PST 2016


 formula/source/core/api/FormulaCompiler.cxx        |   10 ++++------
 formula/source/core/api/token.cxx                  |   17 +++++++++++++++++
 formula/source/core/resource/core_resource.src     |    9 +++++++++
 include/formula/compiler.hrc                       |    3 ++-
 include/formula/opcode.hxx                         |    1 +
 sc/inc/helpids.h                                   |    1 +
 sc/qa/unit/data/contentCSV/date-time-functions.csv |    2 +-
 sc/source/core/inc/interpre.hxx                    |    1 +
 sc/source/core/tool/interpr2.cxx                   |   12 ++++++++++++
 sc/source/core/tool/interpr4.cxx                   |    1 +
 sc/source/filter/excel/xlformula.cxx               |    3 ++-
 11 files changed, 51 insertions(+), 9 deletions(-)

New commits:
commit efeef720de31fe0fab9013f954eac63fe49fa59d
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Jan 5 19:13:54 2016 +0100

    tdf#96198 add WEEKNUM_OOO compatibility function, tdf#50950 follow-up
    
    The remaining cases when loading old and wrong ISOWEEKNUM that can't be
    mapped to either new WEEKNUM or ISOWEEKNUM now are mapped to
    WEEKNUM_OOO(date,mode) with calculations identical to the old and wrong
    OOo WEEKNUM.
    
    These WEEKNUM_OOO cases are still wrongly saved as ISOWEEKNUM so can be
    read by 5.0 or earlier versions as the old WEEKNUM, which should be
    changed for 5.3 or later.
    
    WEEKNUM_OOO is not offered in the Function Wizard to prevent deliberate
    usage.
    
    Also reverts the interim unit test change to
    sc/qa/unit/data/contentCSV/date-time-functions.csv
    that was necessary to catch the error generated by ISOWEEKNUM with two
    arguments.
    
    (cherry picked from commit 902c593196741ffec2d096855369313f6bbe756e)
    
    Conflicts:
    	include/formula/compiler.hrc
    	sc/inc/helpids.h
    	sc/source/filter/excel/xlformula.cxx
    
    Change-Id: I874c4c7225900f03b879f2947512ae02270cbd4f

diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 457beee..526f83f 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -1294,8 +1294,7 @@ void FormulaCompiler::Factor()
                     // literal double value and keep function. Anything else
                     // can not be resolved, there exists no "like ISO but week
                     // starts on Sunday" mode in WEEKNUM and for an expression
-                    // we can't determine, so let ISOWEEKNUM generate an error
-                    // for two arguments in these cases.
+                    // we can't determine.
                     if (pc >= 2 && pArr->nIndex == nSepPos + 3 &&
                             pArr->pCode[nSepPos+1]->GetType() == svDouble &&
                             pArr->pCode[nSepPos+1]->GetDouble() != 1.0 &&
@@ -1309,10 +1308,9 @@ void FormulaCompiler::Factor()
                     }
                     else
                     {
-                        /* FIXME: introduce (hidden?) compatibility function? */
-#if 0
-                        pFacToken->NewOpCode( ocWeeknumCompat, FormulaToken::PrivateAccess());
-#endif
+                        // For the remaining two arguments cases use the
+                        // compatibility function.
+                        pFacToken->NewOpCode( ocWeeknumOOo, FormulaToken::PrivateAccess());
                     }
                 }
                 PutCode( pFacToken );
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index 53bc620..2cd8dec 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -1113,6 +1113,7 @@ inline bool MissingConventionODF::isRewriteNeeded( OpCode eOp ) const
         case ocAddress:
         case ocLogNormDist:
         case ocNormDist:
+        case ocWeeknumOOo:
             return true;
         case ocMissing:
         case ocLog:
@@ -1514,6 +1515,22 @@ FormulaTokenArray * FormulaTokenArray::RewriteMissing( const MissingConvention &
                         ( pCur->GetOpCode() == ocCeil ? ocCeil_Math : ocFloor_Math ) );
                 pNewArr->AddToken( *pToken );
             }
+            else if (pCur->GetOpCode() == ocWeeknumOOo &&
+                    rConv.getConvention() == MissingConvention::FORMULA_MISSING_CONVENTION_ODFF)
+            {
+                /* XXX TODO FIXME: Remove this special handling (also
+                 * ocWeeknumOOo in MissingConventionODF::isRewriteNeeded()
+                 * above) in 5.3 or later, this still abuses the ODFF
+                 * ISOWEEKNUM function to store the old WEEKNUM (now
+                 * WEEKNUM_OOO) cases that can't be mapped to the new WEEKNUM
+                 * or ISOWEEKNUM, as 5.0 and earlier always stored the old
+                 * WEEKNUM as ISOWEEKNUM. Ugly nasty ...
+                 * Later write ORG.LIBREOFFICE.WEEKNUM_OOO, see
+                 * formula/source/core/resource/core_resource.src
+                 * SC_OPCODE_WEEKNUM_OOO */
+                FormulaToken *pToken = new FormulaByteToken( ocIsoWeeknum, pCur->GetByte(), pCur->IsInForceArray());
+                pNewArr->AddToken( *pToken );
+            }
             else
                 pNewArr->AddToken( *pCur );
         }
diff --git a/formula/source/core/resource/core_resource.src b/formula/source/core/resource/core_resource.src
index 90cd6e5..d5db65e 100644
--- a/formula/source/core/resource/core_resource.src
+++ b/formula/source/core/resource/core_resource.src
@@ -391,6 +391,9 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF
     String SC_OPCODE_BETA_INV_MS { Text = "COM.MICROSOFT.BETA.INV" ; };
     String SC_OPCODE_WEEK { Text = "WEEKNUM" ; };
     String SC_OPCODE_ISOWEEKNUM { Text = "ISOWEEKNUM" ; };
+    /* WEEKNUM_OOO currently (5.1) not written, see
+     * formula/source/core/api/token.cxx FormulaTokenArray::RewriteMissing() */
+    String SC_OPCODE_WEEKNUM_OOO { Text = "ORG.LIBREOFFICE.WEEKNUM_OOO" ; };
     String SC_OPCODE_EASTERSUNDAY { Text = "ORG.OPENOFFICE.EASTERSUNDAY" ; };
     String SC_OPCODE_GET_DAY_OF_WEEK { Text = "WEEKDAY" ; };
     String SC_OPCODE_NETWORKDAYS { Text = "NETWORKDAYS" ; };
@@ -813,6 +816,7 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_OOXML
     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_WEEKNUM_OOO { Text = "_xlfn.ORG.LIBREOFFICE.WEEKNUM_OOO" ; };
     String SC_OPCODE_EASTERSUNDAY { Text = "EASTERSUNDAY" ; };
     String SC_OPCODE_GET_DAY_OF_WEEK { Text = "WEEKDAY" ; };
     String SC_OPCODE_NETWORKDAYS { Text = "NETWORKDAYS" ; };
@@ -1237,6 +1241,7 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH
     String SC_OPCODE_BETA_INV_MS { Text = "BETA.INV" ; };
     String SC_OPCODE_WEEK { Text = "WEEKNUM" ; };
     String SC_OPCODE_ISOWEEKNUM { Text = "ISOWEEKNUM" ; };
+    String SC_OPCODE_WEEKNUM_OOO { Text = "WEEKNUM_OOO" ; };
     String SC_OPCODE_EASTERSUNDAY { Text = "EASTERSUNDAY" ; };
     String SC_OPCODE_GET_DAY_OF_WEEK { Text = "WEEKDAY" ; };
     String SC_OPCODE_NETWORKDAYS { Text = "NETWORKDAYS" ; };
@@ -2705,6 +2710,10 @@ Resource RID_STRLIST_FUNCTION_NAMES
     {
         Text [ en-US ] = "ISOWEEKNUM" ;
     };
+    String SC_OPCODE_WEEKNUM_OOO
+    {
+        Text [ en-US ] = "WEEKNUM_OOO" ;
+    };
     String SC_OPCODE_EASTERSUNDAY
     {
         Text [ en-US ] = "EASTERSUNDAY" ;
diff --git a/include/formula/compiler.hrc b/include/formula/compiler.hrc
index 984ec02..2c70f0e 100644
--- a/include/formula/compiler.hrc
+++ b/include/formula/compiler.hrc
@@ -485,7 +485,8 @@
 #define SC_OPCODE_NETWORKDAYS       474
 #define SC_OPCODE_FLOOR_MATH        475
 #define SC_OPCODE_FLOOR_PRECISE     476
-#define SC_OPCODE_STOP_2_PAR        477     /* last function with two or more parameters' OpCode + 1 */
+#define SC_OPCODE_WEEKNUM_OOO       477
+#define SC_OPCODE_STOP_2_PAR        478     /* last function with two or more parameters' OpCode + 1 */
 
 #define SC_OPCODE_STOP_FUNCTION     SC_OPCODE_STOP_2_PAR            /* last function's OpCode + 1 */
 #define SC_OPCODE_LAST_OPCODE_ID    (SC_OPCODE_STOP_FUNCTION - 1)   /* last OpCode */
diff --git a/include/formula/opcode.hxx b/include/formula/opcode.hxx
index 0c4c8e8..f6f3819 100644
--- a/include/formula/opcode.hxx
+++ b/include/formula/opcode.hxx
@@ -450,6 +450,7 @@ enum OpCode : sal_uInt16
     // miscellaneous
         ocWeek              = SC_OPCODE_WEEK,
         ocIsoWeeknum        = SC_OPCODE_ISOWEEKNUM,
+        ocWeeknumOOo        = SC_OPCODE_WEEKNUM_OOO,
         ocGetDayOfWeek      = SC_OPCODE_GET_DAY_OF_WEEK,
         ocNetWorkdays       = SC_OPCODE_NETWORKDAYS,
         ocNetWorkdays_MS    = SC_OPCODE_NETWORKDAYS_MS,
diff --git a/sc/inc/helpids.h b/sc/inc/helpids.h
index 3b41eb8..36188ac 100644
--- a/sc/inc/helpids.h
+++ b/sc/inc/helpids.h
@@ -632,5 +632,6 @@
 #define HID_FUNC_CEIL_MATH                                      "SC_HID_FUNC_CEIL_MATH"
 #define HID_FUNC_FLOOR_MATH                                     "SC_HID_FUNC_FLOOR_MATH"
 #define HID_FUNC_FLOOR_PRECISE                                  "SC_HID_FUNC_FLOOR_PRECISE"
+#define HID_FUNC_WEEKNUM_OOO                                    "SC_HID_FUNC_WEEKNUM_OOO"
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/unit/data/contentCSV/date-time-functions.csv b/sc/qa/unit/data/contentCSV/date-time-functions.csv
index a9e3ddd..09cf42b 100644
--- a/sc/qa/unit/data/contentCSV/date-time-functions.csv
+++ b/sc/qa/unit/data/contentCSV/date-time-functions.csv
@@ -21,7 +21,7 @@
 4,3,4
 52
 1,1,52
-Err:504,52
+1,52
 52
 10,11
 52,52
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 9bdb461..c2686e9 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -619,6 +619,7 @@ void ScGetDay();
 void ScGetDayOfWeek();
 void ScGetWeekOfYear();
 void ScGetIsoWeekOfYear();
+void ScWeeknumOOo();
 void ScEasterSunday();
 sal_uInt16 GetWeekendAndHolidayMasks( const sal_uInt8 nParamCount, const sal_uInt32 nNullDate,
         ::std::vector<double>& rSortArray, bool bWeekendMask[ 7 ] );
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 1777230..ef2277a 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -205,6 +205,18 @@ void ScInterpreter::ScGetDayOfWeek()
     }
 }
 
+void ScInterpreter::ScWeeknumOOo()
+{
+    if ( MustHaveParamCount( GetByte(), 2 ) )
+    {
+        short nFlag = (short) ::rtl::math::approxFloor(GetDouble());
+
+        Date aDate = *(pFormatter->GetNullDate());
+        aDate += (long)::rtl::math::approxFloor(GetDouble());
+        PushInt( (int) aDate.GetWeekOfYear( nFlag == 1 ? SUNDAY : MONDAY ));
+    }
+}
+
 void ScInterpreter::ScGetWeekOfYear()
 {
     sal_uInt8 nParamCount = GetByte();
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index d6b9694..cc0b4bc 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -3701,6 +3701,7 @@ StackVar ScInterpreter::Interpret()
                 case ocGetDayOfWeek     : ScGetDayOfWeek();             break;
                 case ocWeek             : ScGetWeekOfYear();            break;
                 case ocIsoWeeknum       : ScGetIsoWeekOfYear();         break;
+                case ocWeeknumOOo       : ScWeeknumOOo();               break;
                 case ocEasterSunday     : ScEasterSunday();             break;
                 case ocNetWorkdays      : ScNetWorkdays( false);        break;
                 case ocNetWorkdays_MS   : ScNetWorkdays( true );        break;
diff --git a/sc/source/filter/excel/xlformula.cxx b/sc/source/filter/excel/xlformula.cxx
index 5d060cf..e320c6f 100644
--- a/sc/source/filter/excel/xlformula.cxx
+++ b/sc/source/filter/excel/xlformula.cxx
@@ -587,7 +587,8 @@ static const XclFunctionInfo saFuncTable_Odf[] =
 static const XclFunctionInfo saFuncTable_OOoLO[] =
 {
     EXC_FUNCENTRY_OOO( ocConvert,       3,  3,  0,  "ORG.OPENOFFICE.CONVERT" ),
-    EXC_FUNCENTRY_OOO( ocColor,         3,  4,  0,  "ORG.LIBREOFFICE.COLOR" )
+    EXC_FUNCENTRY_OOO( ocColor,         3,  4,  0,  "ORG.LIBREOFFICE.COLOR" ),
+    EXC_FUNCENTRY_OOO( ocWeeknumOOo,    2,  2,  0,  "ORG.LIBREOFFICE.WEEKNUM_OOO" )
 };
 
 #undef EXC_FUNCENTRY_OOO


More information about the Libreoffice-commits mailing list