summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-01-20 23:21:47 +0100
committerCaolán McNamara <caolanm@redhat.com>2017-01-25 12:46:27 +0000
commit4c353b6b858a6027a088dd6a4466690d3d606389 (patch)
tree7fe3229a5186397cdddc296fcd55167485278ec0 /sc
parent37fa60e6289b4c7ed88fd7b107af807211fd1ad9 (diff)
Resolves: tdf#105158 set date or time return type for DATEVALUE TIMEVALUE
... so adding/subtracting another date produces number of days instead of date, and adding/subtracting a number produces date. But if used as the final formula result force number type. Change-Id: I046f5cc53d1fe8c9f6f71876787f2f19d24fe146 (cherry picked from commit b85ee27d9f8039a6442429587598426e73aeb1ba) Reviewed-on: https://gerrit.libreoffice.org/33363 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/tool/interpr2.cxx4
-rw-r--r--sc/source/core/tool/interpr4.cxx29
2 files changed, 28 insertions, 5 deletions
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 0e4245cd74a2..59e87b71ea54 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -177,7 +177,10 @@ void ScInterpreter::ScGetDateValue()
{
short eType = pFormatter->GetType(nFIndex);
if (eType == css::util::NumberFormat::DATE || eType == css::util::NumberFormat::DATETIME)
+ {
+ nFuncFmtType = css::util::NumberFormat::DATE;
PushDouble(::rtl::math::approxFloor(fVal));
+ }
else
PushIllegalArgument();
}
@@ -937,6 +940,7 @@ void ScInterpreter::ScGetTimeValue()
short eType = pFormatter->GetType(nFIndex);
if (eType == css::util::NumberFormat::TIME || eType == css::util::NumberFormat::DATETIME)
{
+ nFuncFmtType = css::util::NumberFormat::TIME;
double fDateVal = rtl::math::approxFloor(fVal);
double fTimeVal = fVal - fDateVal;
PushDouble(fTimeVal);
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 11a8870a8f7b..4c349948972c 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -3879,11 +3879,12 @@ StackVar ScInterpreter::Interpret()
// so reassure exceptions are really off.
SAL_MATH_FPEXCEPTIONS_OFF();
+ OpCode eOp = ocNone;
aCode.Reset();
while( ( pCur = aCode.Next() ) != nullptr
&& (nGlobalError == FormulaError::NONE || nErrorFunction <= nErrorFunctionCount) )
{
- OpCode eOp = pCur->GetOpCode();
+ eOp = pCur->GetOpCode();
cPar = pCur->GetByte();
if ( eOp == ocPush )
{
@@ -4454,6 +4455,21 @@ StackVar ScInterpreter::Interpret()
// End: obtain result
+ bool bForcedResultType;
+ switch (eOp)
+ {
+ case ocGetDateValue:
+ case ocGetTimeValue:
+ // Force final result of DATEVALUE and TIMEVALUE to number type,
+ // which so far was date or time for calculations.
+ nRetTypeExpr = nFuncFmtType = css::util::NumberFormat::NUMBER;
+ nRetIndexExpr = nFuncFmtIndex = 0;
+ bForcedResultType = true;
+ break;
+ default:
+ bForcedResultType = false;
+ }
+
if( sp )
{
pCur = pStack[ sp-1 ];
@@ -4476,9 +4492,12 @@ StackVar ScInterpreter::Interpret()
if (pCur->GetDoubleType())
{
const double fVal = PopDouble();
- if (nCurFmtType != nFuncFmtType)
- nRetIndexExpr = 0; // carry format index only for matching type
- nRetTypeExpr = nFuncFmtType = nCurFmtType;
+ if (!bForcedResultType)
+ {
+ if (nCurFmtType != nFuncFmtType)
+ nRetIndexExpr = 0; // carry format index only for matching type
+ nRetTypeExpr = nFuncFmtType = nCurFmtType;
+ }
PushTempToken( new FormulaDoubleToken( fVal));
}
if ( nFuncFmtType == css::util::NumberFormat::UNDEFINED )
@@ -4573,7 +4592,7 @@ StackVar ScInterpreter::Interpret()
else
SetError( FormulaError::NoCode);
- if( nRetTypeExpr != css::util::NumberFormat::UNDEFINED )
+ if (bForcedResultType || nRetTypeExpr != css::util::NumberFormat::UNDEFINED)
{
nRetFmtType = nRetTypeExpr;
nRetFmtIndex = nRetIndexExpr;