[Libreoffice-commits] core.git: Branch 'libreoffice-5-2' - sc/source

Eike Rathke erack at redhat.com
Wed Jun 15 10:58:22 UTC 2016


 sc/source/core/tool/interpr2.cxx |   36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

New commits:
commit be710eef2f8e408b38d8a90aee5c45e2d1a936a2
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Jun 15 12:36:55 2016 +0200

    Resolves: tdf#100396 handle unspecified WEEKDAY arguments and support new ones
    
    ... introduced with Excel 2010.
    
    Change-Id: Ide47fea0e8bc109dc47f591c33ec1d1a13c08d72
    (cherry picked from commit d9911e0d13c96feb0b0d1feacef6be7be29ccfe1)
    Reviewed-on: https://gerrit.libreoffice.org/26297
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index b0d8f6d..773eaba 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -196,16 +196,36 @@ void ScInterpreter::ScGetDayOfWeek()
 
         Date aDate = *(pFormatter->GetNullDate());
         aDate += (long)::rtl::math::approxFloor(GetDouble());
-        int nVal = (int) aDate.GetDayOfWeek();
-        if (nFlag == 1)
+        int nVal = (int) aDate.GetDayOfWeek();  // MONDAY = 0
+        switch (nFlag)
         {
-            if (nVal == 6)
-                nVal = 1;
-            else
-                nVal += 2;
+            case 1:     // Sunday = 1
+                if (nVal == 6)
+                    nVal = 1;
+                else
+                    nVal += 2;
+            break;
+            case 2:     // Monday = 1
+                nVal += 1;
+            break;
+            case 3:     // Monday = 0
+                ;   // nothing
+            break;
+            case 11:    // Monday = 1
+            case 12:    // Tuesday = 1
+            case 13:    // Wednesday = 1
+            case 14:    // Thursday = 1
+            case 15:    // Friday = 1
+            case 16:    // Saturday = 1
+            case 17:    // Sunday = 1
+                if (nVal < nFlag - 11)      // x = nFlag - 11 = 0,1,2,3,4,5,6
+                    nVal += 19 - nFlag;     // nVal += (8 - (nFlag - 11) = 8 - x = 8,7,6,5,4,3,2)
+                else
+                    nVal -= nFlag - 12;     // nVal -= ((nFlag - 11) - 1 = x - 1 = -1,0,1,2,3,4,5)
+            break;
+            default:
+                SetError( errIllegalArgument);
         }
-        else if (nFlag == 2)
-            nVal += 1;
         PushInt( nVal );
     }
 }


More information about the Libreoffice-commits mailing list