From e055b4a0fc23e1d0ad5d498f9195790dd41f6b3e Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Tue, 28 Aug 2018 16:59:26 +0200 Subject: Use tools::Time::GetClock() to obtain hour,minute,second ... instead of rtl::math::approxFloor(fValue*DATE_TIME_FACTOR+0.5) seconds that most times works but sometimes not. Change-Id: Iaca69630461f2067622898fab35cda61d20172a9 Reviewed-on: https://gerrit.libreoffice.org/59719 Reviewed-by: Eike Rathke Tested-by: Jenkins --- sc/source/core/data/dpgroup.cxx | 16 +++++++--------- sc/source/core/data/dputil.cxx | 13 +++++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx index 70b326b8c5a7..92a6810d968d 100644 --- a/sc/source/core/data/dpgroup.cxx +++ b/sc/source/core/data/dpgroup.cxx @@ -169,31 +169,29 @@ bool ScDPGroupDateFilter::match( const ScDPItemData & rCellData ) const nGroupType == DataPilotFieldGroupBy::SECONDS) { // handle time - // (as in the cell functions, ScInterpreter::ScGetHour etc.: seconds are rounded) + // (do as in the cell functions, ScInterpreter::ScGetHour() etc.) - double time = rCellData.GetValue() - approxFloor(rCellData.GetValue()); - long seconds = static_cast(approxFloor(time*DATE_TIME_FACTOR + 0.5)); + sal_uInt16 nHour, nMinute, nSecond; + double fFractionOfSecond; + tools::Time::GetClock( rCellData.GetValue(), nHour, nMinute, nSecond, fFractionOfSecond, 0); switch (nGroupType) { case DataPilotFieldGroupBy::HOURS: { - sal_Int32 hrs = seconds / 3600; - if (hrs == nValue) + if (nHour == nValue) return true; } break; case DataPilotFieldGroupBy::MINUTES: { - sal_Int32 minutes = (seconds % 3600) / 60; - if (minutes == nValue) + if (nMinute == nValue) return true; } break; case DataPilotFieldGroupBy::SECONDS: { - sal_Int32 sec = seconds % 60; - if (sec == nValue) + if (nSecond == nValue) return true; } break; diff --git a/sc/source/core/data/dputil.cxx b/sc/source/core/data/dputil.cxx index 6afdc101a006..aefa1e143bcb 100644 --- a/sc/source/core/data/dputil.cxx +++ b/sc/source/core/data/dputil.cxx @@ -314,21 +314,22 @@ sal_Int32 ScDPUtil::getDatePartValue( nDatePart == sheet::DataPilotFieldGroupBy::SECONDS) { // handle time - // (as in the cell functions, ScInterpreter::ScGetHour etc.: seconds are rounded) + // (do as in the cell functions, ScInterpreter::ScGetHour() etc.) - double fTime = fValue - rtl::math::approxFloor(fValue); - long nSeconds = static_cast(rtl::math::approxFloor(fTime*DATE_TIME_FACTOR+0.5)); + sal_uInt16 nHour, nMinute, nSecond; + double fFractionOfSecond; + tools::Time::GetClock( fValue, nHour, nMinute, nSecond, fFractionOfSecond, 0); switch (nDatePart) { case sheet::DataPilotFieldGroupBy::HOURS: - nResult = nSeconds / 3600; + nResult = nHour; break; case sheet::DataPilotFieldGroupBy::MINUTES: - nResult = ( nSeconds % 3600 ) / 60; + nResult = nMinute; break; case sheet::DataPilotFieldGroupBy::SECONDS: - nResult = nSeconds % 60; + nResult = nSecond; break; } } -- cgit