diff options
author | Eike Rathke <erack@redhat.com> | 2016-06-15 12:36:55 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-06-15 12:47:58 +0200 |
commit | d9911e0d13c96feb0b0d1feacef6be7be29ccfe1 (patch) | |
tree | ef1262ec73fc41185a42de910fe76d7c39f98458 | |
parent | 2afe8701aefab454c8bf1dcc063227ea9d290dcb (diff) |
Resolves: tdf#100396 handle unspecified WEEKDAY arguments and support new ones
... introduced with Excel 2010.
Change-Id: Ide47fea0e8bc109dc47f591c33ec1d1a13c08d72
-rw-r--r-- | sc/source/core/tool/interpr2.cxx | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index df32da36d08f..812c858dcd7f 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 ); } } |