[Libreoffice-commits] core.git: sc/source

Eike Rathke erack at redhat.com
Wed Jun 15 10:48:27 UTC 2016


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

New commits:
commit d9911e0d13c96feb0b0d1feacef6be7be29ccfe1
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

diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index df32da3..812c858 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -197,16 +197,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