From d77495060016c5e97d6e367c2a44fec83cf441f2 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Fri, 10 May 2019 17:26:57 +0200 Subject: Apply duration format for such newly entered formula cells ... and the cell didn't have a number format applied already, [HH]:MM:SS instead of wall clock time format HH:MM:SS which comes to a surprise anyway if the result is >=24h. Related to tdf#125099 Change-Id: I6c19a86177f8714ac588d6798acf86e247a79b26 Reviewed-on: https://gerrit.libreoffice.org/72131 Reviewed-by: Eike Rathke Tested-by: Jenkins --- svl/source/numbers/zforlist.cxx | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'svl') diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index 01b9453ed9eb..705e0624c785 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -68,6 +68,7 @@ using namespace ::std; #define ZF_STANDARD_CURRENCY 20 #define ZF_STANDARD_DATE 30 #define ZF_STANDARD_TIME 40 +#define ZF_STANDARD_DURATION (ZF_STANDARD_TIME + 4) #define ZF_STANDARD_DATETIME 50 #define ZF_STANDARD_SCIENTIFIC 60 #define ZF_STANDARD_FRACTION 65 @@ -1224,6 +1225,8 @@ bool SvNumberFormatter::IsCompatible(SvNumFormatType eOldType, SvNumFormatType e return false; } break; + case SvNumFormatType::DURATION: + return false; default: return false; } @@ -1246,6 +1249,9 @@ sal_uInt32 SvNumberFormatter::ImpGetDefaultFormat( SvNumFormatType nType ) case SvNumFormatType::DATETIME: nSearch = CLOffset + ZF_STANDARD_DATETIME; break; + case SvNumFormatType::DURATION: + nSearch = CLOffset + ZF_STANDARD_DURATION; + break; case SvNumFormatType::PERCENT: nSearch = CLOffset + ZF_STANDARD_PERCENT; break; @@ -1289,6 +1295,9 @@ sal_uInt32 SvNumberFormatter::ImpGetDefaultFormat( SvNumFormatType nType ) case SvNumFormatType::DATETIME: nDefaultFormat = CLOffset + ZF_STANDARD_DATETIME; break; + case SvNumFormatType::DURATION: + nDefaultFormat = CLOffset + ZF_STANDARD_DURATION; + break; case SvNumFormatType::PERCENT: nDefaultFormat = CLOffset + ZF_STANDARD_PERCENT+1; break; @@ -1317,6 +1326,8 @@ sal_uInt32 SvNumberFormatter::GetStandardFormat( SvNumFormatType eType, Language { case SvNumFormatType::CURRENCY: return ( eLnge == LANGUAGE_SYSTEM ) ? ImpGetDefaultSystemCurrencyFormat() : ImpGetDefaultCurrencyFormat(); + case SvNumFormatType::DURATION : + return GetFormatIndex( NF_TIME_HH_MMSS, eLnge); case SvNumFormatType::DATE: case SvNumFormatType::TIME: case SvNumFormatType::DATETIME: @@ -1359,7 +1370,7 @@ sal_uInt32 SvNumberFormatter::GetStandardFormat( sal_uInt32 nFIndex, SvNumFormat return GetStandardFormat( eType, eLnge ); } -sal_uInt32 SvNumberFormatter::GetTimeFormat( double fNumber, LanguageType eLnge ) +sal_uInt32 SvNumberFormatter::GetTimeFormat( double fNumber, LanguageType eLnge, bool bForceDuration ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); bool bSign; @@ -1373,14 +1384,14 @@ sal_uInt32 SvNumberFormatter::GetTimeFormat( double fNumber, LanguageType eLnge double fSeconds = fNumber * 86400; if ( floor( fSeconds + 0.5 ) * 100 != floor( fSeconds * 100 + 0.5 ) ) { // with 100th seconds - if ( bSign || fSeconds >= 3600 ) + if ( bForceDuration || bSign || fSeconds >= 3600 ) return GetFormatIndex( NF_TIME_HH_MMSS00, eLnge ); else return GetFormatIndex( NF_TIME_MMSS00, eLnge ); } else { - if ( bSign || fNumber >= 1.0 ) + if ( bForceDuration || bSign || fNumber >= 1.0 ) return GetFormatIndex( NF_TIME_HH_MMSS, eLnge ); else return GetStandardFormat( SvNumFormatType::TIME, eLnge ); @@ -1396,8 +1407,10 @@ sal_uInt32 SvNumberFormatter::GetStandardFormat( double fNumber, sal_uInt32 nFIn switch( eType ) { + case SvNumFormatType::DURATION : + return GetTimeFormat( fNumber, eLnge, true); case SvNumFormatType::TIME : - return GetTimeFormat( fNumber, eLnge); + return GetTimeFormat( fNumber, eLnge, false); default: return GetStandardFormat( eType, eLnge ); } @@ -1414,13 +1427,15 @@ sal_uInt32 SvNumberFormatter::GuessDateTimeFormat( SvNumFormatType& rType, doubl { // Clearly a time. rType = SvNumFormatType::TIME; - nRet = GetTimeFormat( fNumber, eLnge); + nRet = GetTimeFormat( fNumber, eLnge, false); } else if (fabs( fNumber) * 24 < 0x7fff) { - // Assuming time within 32k hours or 3.7 years. + // Assuming duration within 32k hours or 3.7 years. + // This should be SvNumFormatType::DURATION instead, but the outer + // world can't cope with that. rType = SvNumFormatType::TIME; - nRet = GetTimeFormat( fNumber, eLnge); + nRet = GetTimeFormat( fNumber, eLnge, true); } else if (rtl::math::approxFloor( fNumber) != fNumber) { @@ -1479,7 +1494,7 @@ sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex, * of a signed 16-bit. 32k hours are 3.7 years ... or * 1903-09-26 if date. */ if (fabs( fNumber) * 24 < 0x7fff) - nKey = GetFormatIndex( NF_TIME_HH_MMSS, eLang ); + nKey = GetTimeFormat( fNumber, eLang, true); // Preserve duration, use [HH]:MM:SS instead of time. else nKey = GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eLang ); @@ -1489,6 +1504,9 @@ sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex, else nKey = GetStandardFormat( fNumber, nFIndex, eType, eLang ); break; + case SvNumFormatType::DURATION : + nKey = GetTimeFormat( fNumber, eLang, true); + break; case SvNumFormatType::DATETIME : if (nFIndex == GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS, eLang) || (pFormat && pFormat->IsIso8601( 0 ))) nKey = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS, eLang ); -- cgit