diff options
author | Eike Rathke <erack@redhat.com> | 2017-01-20 23:21:47 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-01-20 23:31:48 +0100 |
commit | b85ee27d9f8039a6442429587598426e73aeb1ba (patch) | |
tree | ff002e462e6c5b8f368726c06ed16c3fc4a4628f /sc | |
parent | 7a38fa97e0423ac601848c701944aa3f81a17c5c (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
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/interpr2.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/interpr4.cxx | 29 |
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 94d04acfaf2c..f32099e8fecd 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; |