sc/source/core/tool/interpr2.cxx | 4 ++++ sc/source/core/tool/interpr4.cxx | 29 ++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-)
New commits: commit b85ee27d9f8039a6442429587598426e73aeb1ba Author: Eike Rathke <er...@redhat.com> Date: Fri Jan 20 23:21:47 2017 +0100 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 diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index 0e4245c..59e87b7 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 94d04ac..f32099e 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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits