summaryrefslogtreecommitdiff
path: root/svl/source
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2022-10-24 14:56:55 +0200
committerEike Rathke <erack@redhat.com>2022-10-24 17:07:18 +0200
commit5ce6de864380f1eabbd78656ff6cc31920c534d2 (patch)
tree613973c353265a8b3b20ebea7440008a67344923 /svl/source
parentfe0795c52f783a0cfb9e90aab4ae6fac4eac68df (diff)
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 <erack@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'svl/source')
-rw-r--r--svl/source/numbers/zformat.cxx13
1 files changed, 8 insertions, 5 deletions
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