svl/source/numbers/zformat.cxx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
New commits: commit 5ce6de864380f1eabbd78656ff6cc31920c534d2 Author: Eike Rathke <[email protected]> AuthorDate: Mon Oct 24 14:56:55 2022 +0200 Commit: Eike Rathke <[email protected]> CommitDate: Mon Oct 24 17:07:18 2022 +0200 Related: tdf#136615 Do not round a DateTime clock format into the next day =TEXT(44858+86399.99/86400;"yyyy-mm-dd hh:mm:ss") gave 2022-10-25 00:00:00 instead of 2022-10-24 23:59:59 whereas =TEXT(44858+86399.99/86400;"yyyy-mm-dd hh:mm:ss.000") correctly results in 2022-10-24 23:59:59.990 Change-Id: Ib2ec5281eeb8590023e5137e816a8ad8fde2a8ca Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141764 Reviewed-by: Eike Rathke <[email protected]> Tested-by: Jenkins diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 39883619f4d0..b3a547c28d3f 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -3953,21 +3953,24 @@ bool SvNumberformat::ImpGetDateTimeOutput(double fNumber, const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); bool bInputLine; - sal_Int32 nCntPost; + sal_Int32 nCntPost, nFirstRounding; + // Round at 7 decimals (+5 of 86400 == 12 significant digits). + constexpr sal_Int32 kSignificantRound = 7; if ( rScan.GetStandardPrec() == SvNumberFormatter::INPUTSTRING_PRECISION && - 0 < rInfo.nCntPost && rInfo.nCntPost < 7 ) + 0 < rInfo.nCntPost && rInfo.nCntPost < kSignificantRound ) { - // round at 7 decimals (+5 of 86400 == 12 significant digits) bInputLine = true; - nCntPost = 7; + nCntPost = nFirstRounding = kSignificantRound; } else { bInputLine = false; nCntPost = rInfo.nCntPost; + // For clock format (not []) do not round up to seconds and thus days. + nFirstRounding = (rInfo.bThousand ? nCntPost : kSignificantRound); } double fTime = (fNumber - floor( fNumber )) * 86400.0; - fTime = ::rtl::math::round( fTime, int(nCntPost) ); + fTime = ::rtl::math::round( fTime, int(nFirstRounding) ); if (fTime >= 86400.0) { // result of fNumber==x.999999999... rounded up, use correct date/time
