diff options
author | Eike Rathke <erack@redhat.com> | 2019-05-07 23:17:45 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2019-05-08 01:05:51 +0200 |
commit | 85c0521f01f5c726e9f754b3175a550121e566c8 (patch) | |
tree | 7a61fd57972284c68b7149ce6a57c0e4b1798c66 /sc | |
parent | 8de7949050d63fd9f7ac41e1a2442849580b86fa (diff) |
Resolves: tdf#125099 round duration results in interpreter already
So wall clock time formats less likely display a one-off value,
duration formats are too rarely used if the expected duration is
less than 24 hours.
Change-Id: I9b0872420699b17e3ed3f20993f8cfe02761f862
Reviewed-on: https://gerrit.libreoffice.org/71909
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/interpr4.cxx | 21 | ||||
-rw-r--r-- | sc/source/core/tool/interpr5.cxx | 9 |
2 files changed, 26 insertions, 4 deletions
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index 5713a5bd5fdc..286583e875c5 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -4423,6 +4423,7 @@ StackVar ScInterpreter::Interpret() case SvNumFormatType::DATE: case SvNumFormatType::TIME: case SvNumFormatType::DATETIME: + case SvNumFormatType::DURATION: nRetIndexExpr = nFuncFmtIndex; break; default: @@ -4537,13 +4538,26 @@ StackVar ScInterpreter::Interpret() // unnecessarily duplicate the information. if (pCur->GetDoubleType() != 0) { - const double fVal = PopDouble(); + double fVal = PopDouble(); if (!bForcedResultType) { if (nCurFmtType != nFuncFmtType) nRetIndexExpr = 0; // carry format index only for matching type nRetTypeExpr = nFuncFmtType = nCurFmtType; } + if (nRetTypeExpr == SvNumFormatType::DURATION) + { + // Round the duration in case a wall clock time + // display format is used instead of a duration + // format. To micro seconds which then catches + // the converted hh:mm:ss.9999997 cases. + if (fVal != 0.0) + { + fVal *= 86400.0; + fVal = rtl::math::round( fVal, 6); + fVal /= 86400.0; + } + } PushTempToken( CreateFormulaDoubleToken( fVal)); } if ( nFuncFmtType == SvNumFormatType::UNDEFINED ) @@ -4653,6 +4667,11 @@ StackVar ScInterpreter::Interpret() else nRetFmtType = SvNumFormatType::NUMBER; + // Currently (2019-05-06) nothing else can cope with a duration format + // type, change to time as it was before. + if (nRetFmtType == SvNumFormatType::DURATION) + nRetFmtType = SvNumFormatType::TIME; + if (nGlobalError != FormulaError::NONE && GetStackType() != svError ) PushError( nGlobalError); diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx index 504233a997a4..e928b974d110 100644 --- a/sc/source/core/tool/interpr5.cxx +++ b/sc/source/core/tool/interpr5.cxx @@ -1126,15 +1126,16 @@ ScMatrixRef ScInterpreter::MatConcat(const ScMatrixRef& pMat1, const ScMatrixRef return xResMat; } -// for DATE, TIME, DATETIME +// for DATE, TIME, DATETIME, DURATION static void lcl_GetDiffDateTimeFmtType( SvNumFormatType& nFuncFmt, SvNumFormatType nFmt1, SvNumFormatType nFmt2 ) { if ( nFmt1 != SvNumFormatType::UNDEFINED || nFmt2 != SvNumFormatType::UNDEFINED ) { if ( nFmt1 == nFmt2 ) { - if ( nFmt1 == SvNumFormatType::TIME || nFmt1 == SvNumFormatType::DATETIME ) - nFuncFmt = SvNumFormatType::TIME; // times result in time + if ( nFmt1 == SvNumFormatType::TIME || nFmt1 == SvNumFormatType::DATETIME + || nFmt1 == SvNumFormatType::DURATION ) + nFuncFmt = SvNumFormatType::DURATION; // times result in time duration // else: nothing special, number (date - date := days) } else if ( nFmt1 == SvNumFormatType::UNDEFINED ) @@ -1178,6 +1179,7 @@ void ScInterpreter::CalculateAddSub(bool _bSub) case SvNumFormatType::DATE : case SvNumFormatType::TIME : case SvNumFormatType::DATETIME : + case SvNumFormatType::DURATION : nFmt2 = nCurFmtType; break; case SvNumFormatType::CURRENCY : @@ -1200,6 +1202,7 @@ void ScInterpreter::CalculateAddSub(bool _bSub) case SvNumFormatType::DATE : case SvNumFormatType::TIME : case SvNumFormatType::DATETIME : + case SvNumFormatType::DURATION : nFmt1 = nCurFmtType; break; case SvNumFormatType::CURRENCY : |