From f01e31762b02b8b896e726238eb2475c0e01ef82 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Tue, 7 May 2019 23:17:45 +0200 Subject: [PATCH] Resolves: tdf#125099 round duration results in interpreter already MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a combination of 3 commits. 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. Reviewed-on: https://gerrit.libreoffice.org/71909 Tested-by: Jenkins Reviewed-by: Eike Rathke (cherry picked from commit 85c0521f01f5c726e9f754b3175a550121e566c8) Test RANK(), not the underlying floating point representation of duration The RANK() results depended on the floating point representation of time differences (durations), which for visually equal MM:SS display values don't have to be equal if similar durations result from different start and end times. Change that to a well defined duration in seconds. b69a6b43f48abd2d4fe605021acfd2800e75b5e1 Reviewed-on: https://gerrit.libreoffice.org/71926 Reviewed-by: Eike Rathke Tested-by: Jenkins (cherry picked from commit 8de7949050d63fd9f7ac41e1a2442849580b86fa) Fix typed flags bitmask, tdf#125099 follow-up 25327cfcafc9e1f2e88b388677853c638dd9b0e6 Reviewed-on: https://gerrit.libreoffice.org/71946 Reviewed-by: Eike Rathke Tested-by: Jenkins (cherry picked from commit d27ad84ec7a0aafb07d6a6152c686f4bc802f661) Change-Id: I9b0872420699b17e3ed3f20993f8cfe02761f862 Reviewed-on: https://gerrit.libreoffice.org/71935 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- include/svl/zforlist.hxx | 7 +- offapi/com/sun/star/util/NumberFormat.idl | 7 + .../data/functions/statistical/fods/rank.fods | 739 +++++++----------- sc/source/core/tool/interpr4.cxx | 21 +- sc/source/core/tool/interpr5.cxx | 9 +- 5 files changed, 317 insertions(+), 466 deletions(-) diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx index 143d14e03f50..cf7b1dec34a9 100644 --- a/include/svl/zforlist.hxx +++ b/include/svl/zforlist.hxx @@ -109,9 +109,14 @@ enum class SvNumFormatType : sal_Int16 @since LibreOffice 5.1 */ EMPTY = css::util::NumberFormat::EMPTY, // 4096 + /** @internal selects a time duration format. + 8192 + TIME (4) + @since LibreOffice 6.2 + */ + DURATION = css::util::NumberFormat::DURATION, // 8196 }; namespace o3tl { - template<> struct typed_flags : is_typed_flags {}; + template<> struct typed_flags : is_typed_flags {}; } /** enum values for SvNumberFormatter::GetFormatIndex diff --git a/offapi/com/sun/star/util/NumberFormat.idl b/offapi/com/sun/star/util/NumberFormat.idl index 2bc297aed425..e66a59d7e215 100644 --- a/offapi/com/sun/star/util/NumberFormat.idl +++ b/offapi/com/sun/star/util/NumberFormat.idl @@ -99,6 +99,13 @@ published constants NumberFormat */ const short EMPTY = 4096; + + /** @internal selects a time duration format. + 8192 + TIME (4) + @since LibreOffice 6.2 + */ + const short DURATION = 8196; + }; diff --git a/sc/qa/unit/data/functions/statistical/fods/rank.fods b/sc/qa/unit/data/functions/statistical/fods/rank.fods index 880f3659032b..d12703d5ee55 100644 --- a/sc/qa/unit/data/functions/statistical/fods/rank.fods +++ b/sc/qa/unit/data/functions/statistical/fods/rank.fods @@ -1,12 +1,12 @@ - 2017-01-02T17:08:37.518406343P0D1LibreOfficeDev/5.4.0.0.alpha0$Linux_X86_64 LibreOffice_project/ea860d52ade14b4a16289c81a0f8586799c6617f + 2017-01-02T17:08:37.518406343P0D1LibreOfficeDev/6.1.6.3.0$Linux_X86_64 LibreOffice_project/47b704879f52819423702f4efa17cbae8d7b7afa 0 0 - 58986 + 53248 8995 @@ -32,7 +32,7 @@ 4 - 1 + 10 0 0 0 @@ -50,7 +50,7 @@ Sheet2 - 1241 + 1861 0 100 60 @@ -58,7 +58,7 @@ true true true - 12632256 + 12632256 true true true @@ -77,24 +77,13 @@ 7 - false - false true - true - false - false - false - 1270 - 1270 - true - true - true - true - true false - 12632256 - false - Lexmark-E352dn + false + 0 + false + lwH+/0dlbmVyaWMgUHJpbnRlcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU0dFTlBSVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWAAMAuAAAAAAAAAAIAFZUAAAkbQAASm9iRGF0YSAxCnByaW50ZXI9R2VuZXJpYyBQcmludGVyCm9yaWVudGF0aW9uPVBvcnRyYWl0CmNvcGllcz0xCmNvbGxhdGU9ZmFsc2UKbWFyZ2luZGFqdXN0bWVudD0wLDAsMCwwCmNvbG9yZGVwdGg9MjQKcHNsZXZlbD0wCnBkZmRldmljZT0xCmNvbG9yZGV2aWNlPTAKUFBEQ29udGV4RGF0YQpQYWdlU2l6ZTpMZXR0ZXIAABIAQ09NUEFUX0RVUExFWF9NT0RFDwBEdXBsZXhNb2RlOjpPZmY= + Generic Printer cs @@ -125,16 +114,28 @@ - true - true + true 3 - 1 true + false + true + true + 12632256 + true + true + false + true + false + true + false + true 1 - true - lgH+/0xleG1hcmstRTM1MmRuAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQ1VQUzpMZXhtYXJrLUUzNTJkbgAAAAAAAAAAAAAAAAAWAAMAtwAAAAAAAAAIAFZUAAAkbQAASm9iRGF0YSAxCnByaW50ZXI9TGV4bWFyay1FMzUyZG4Kb3JpZW50YXRpb249UG9ydHJhaXQKY29waWVzPTEKY29sbGF0ZT1mYWxzZQptYXJnaW5kYWp1c3RtZW50PTAsMCwwLDAKY29sb3JkZXB0aD0yNApwc2xldmVsPTAKcGRmZGV2aWNlPTEKY29sb3JkZXZpY2U9MApQUERDb250ZXhEYXRhClBhZ2VTaXplOkxldHRlcgAAEgBDT01QQVRfRFVQTEVYX01PREUPAER1cGxleE1vZGU6Ok9mZg== - false - 0 + false + 1270 + 1270 + false + 1 + true @@ -159,9 +160,11 @@ + + @@ -2971,6 +2974,9 @@ + + + @@ -3100,9 +3106,6 @@ - - - @@ -3163,31 +3166,25 @@ - + - + + + + - + - - - - - - - - - - - + + @@ -3215,13 +3212,6 @@ - - - - - - - @@ -3253,26 +3243,19 @@ - + - + - - - - - - - @@ -3389,15 +3372,15 @@ - ??? (???) + ???(???) - 00/00/0000, 00:00:00 + 00/00/0000, 00:00:00 - Page 1 / 99 + Page 1/ 99 @@ -3449,7 +3432,7 @@ - + Sheet @@ -3460,11 +3443,11 @@ Description - + 1 - + TRUE @@ -3481,27 +3464,7 @@ - - - - - - - - - - - - - - - - - - - - - + @@ -3513,16 +3476,11 @@ - + - - - - - @@ -3538,16 +3496,15 @@ - - + - + - + - + Function @@ -3581,7 +3538,7 @@ finish time - time taken + time taken (s) @@ -3592,17 +3549,17 @@ - + - + 4 4 - + TRUE @@ -3633,18 +3590,18 @@ - + - + 3 3 - + TRUE @@ -3667,8 +3624,8 @@ 34:45 - - 17:34 + + 1054 @@ -3683,17 +3640,17 @@ - + - + 3 3 - + TRUE @@ -3714,8 +3671,8 @@ 34:47 - - 17:35 + + 1055 @@ -3729,17 +3686,17 @@ - + - + 5 5 - + TRUE @@ -3757,8 +3714,8 @@ 34:45 - - 17:32 + + 1052 @@ -3768,17 +3725,17 @@ - + - - - 6 + + + 5 - - 6 + + 5 - + TRUE @@ -3796,8 +3753,8 @@ 34:43 - - 17:29 + + 1049 @@ -3805,17 +3762,17 @@ - + - + 7 7 - + TRUE @@ -3831,24 +3788,24 @@ 34:50 - - 17:34 + + 1054 - + - + 4 4 - + TRUE @@ -3865,8 +3822,8 @@ 34:45 - - 17:28 + + 1048 @@ -3874,17 +3831,17 @@ - + - + 2 2 - + TRUE @@ -3900,8 +3857,8 @@ 34:47 - - 17:29 + + 1049 @@ -3909,17 +3866,17 @@ - + - + 5 5 - + TRUE @@ -3934,17 +3891,17 @@ - + - + 1 1 - + TRUE @@ -3956,22 +3913,22 @@ - + - + - - - 3 + + + 2 - - 3 + + 2 - + TRUE @@ -3985,21 +3942,21 @@ - + - + - + #VALUE! #VALUE! - + TRUE @@ -4010,20 +3967,20 @@ - + - + - + 3 3 - + TRUE @@ -4034,20 +3991,20 @@ - + - + - + 3 3 - + TRUE @@ -4060,16 +4017,16 @@ - + - + - + - + @@ -4078,16 +4035,16 @@ - + - + - + - + @@ -4097,16 +4054,16 @@ - + - + - + - + @@ -4116,16 +4073,16 @@ - + - + - + - + @@ -4134,16 +4091,16 @@ - + - + - + - + @@ -4152,32 +4109,32 @@ - + - + - + - + - + - + - + - + @@ -4186,16 +4143,16 @@ - + - + - + - + @@ -4204,64 +4161,64 @@ - + - + - + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + @@ -4270,80 +4227,80 @@ - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + @@ -4352,382 +4309,242 @@ - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index cc3672cbdbeb..57ab5aec29a2 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -4433,6 +4433,7 @@ StackVar ScInterpreter::Interpret() case SvNumFormatType::DATE: case SvNumFormatType::TIME: case SvNumFormatType::DATETIME: + case SvNumFormatType::DURATION: nRetIndexExpr = nFuncFmtIndex; break; default: @@ -4547,13 +4548,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 ) @@ -4663,6 +4677,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 b18ddd7fb673..aefb26c920e3 100644 --- a/sc/source/core/tool/interpr5.cxx +++ b/sc/source/core/tool/interpr5.cxx @@ -1129,15 +1129,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 ) @@ -1181,6 +1182,7 @@ void ScInterpreter::CalculateAddSub(bool _bSub) case SvNumFormatType::DATE : case SvNumFormatType::TIME : case SvNumFormatType::DATETIME : + case SvNumFormatType::DURATION : nFmt2 = nCurFmtType; break; case SvNumFormatType::CURRENCY : @@ -1203,6 +1205,7 @@ void ScInterpreter::CalculateAddSub(bool _bSub) case SvNumFormatType::DATE : case SvNumFormatType::TIME : case SvNumFormatType::DATETIME : + case SvNumFormatType::DURATION : nFmt1 = nCurFmtType; break; case SvNumFormatType::CURRENCY : -- 2.21.0