Use constexpr kTimeSignificantRound for all occurrences

Change-Id: I3d55c5ee0d0e7a803f95c0fe9f67ee15fe814b65
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141773
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
This commit is contained in:
Eike Rathke
2022-10-24 17:06:09 +02:00
parent 6d4e290bfd
commit c3247f0380

View File

@@ -62,6 +62,8 @@ const double EXP_ABS_UPPER_BOUND = 1.0E15; // use exponential notation above th
// also sal/rtl/math.cxx // also sal/rtl/math.cxx
// doubleToString() // doubleToString()
constexpr sal_Int32 kTimeSignificantRound = 7; // Round (date+)time at 7 decimals
// (+5 of 86400 == 12 significant digits).
} // namespace } // namespace
const double D_MAX_U_INT32 = double(0xffffffff); // 4294967295.0 const double D_MAX_U_INT32 = double(0xffffffff); // 4294967295.0
@@ -3069,10 +3071,10 @@ bool SvNumberformat::ImpGetTimeOutput(double fNumber,
bool bInputLine; bool bInputLine;
sal_Int32 nCntPost; sal_Int32 nCntPost;
if ( rScan.GetStandardPrec() == SvNumberFormatter::INPUTSTRING_PRECISION && if ( rScan.GetStandardPrec() == SvNumberFormatter::INPUTSTRING_PRECISION &&
0 < rInfo.nCntPost && rInfo.nCntPost < 7 ) 0 < rInfo.nCntPost && rInfo.nCntPost < kTimeSignificantRound )
{ // round at 7 decimals (+5 of 86400 == 12 significant digits) {
bInputLine = true; bInputLine = true;
nCntPost = 7; nCntPost = kTimeSignificantRound;
} }
else else
{ {
@@ -3954,20 +3956,18 @@ bool SvNumberformat::ImpGetDateTimeOutput(double fNumber,
const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info();
bool bInputLine; bool bInputLine;
sal_Int32 nCntPost, nFirstRounding; 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 && if ( rScan.GetStandardPrec() == SvNumberFormatter::INPUTSTRING_PRECISION &&
0 < rInfo.nCntPost && rInfo.nCntPost < kSignificantRound ) 0 < rInfo.nCntPost && rInfo.nCntPost < kTimeSignificantRound )
{ {
bInputLine = true; bInputLine = true;
nCntPost = nFirstRounding = kSignificantRound; nCntPost = nFirstRounding = kTimeSignificantRound;
} }
else else
{ {
bInputLine = false; bInputLine = false;
nCntPost = rInfo.nCntPost; nCntPost = rInfo.nCntPost;
// For clock format (not []) do not round up to seconds and thus days. // For clock format (not []) do not round up to seconds and thus days.
nFirstRounding = (rInfo.bThousand ? nCntPost : kSignificantRound); nFirstRounding = (rInfo.bThousand ? nCntPost : kTimeSignificantRound);
} }
double fTime = (fNumber - floor( fNumber )) * 86400.0; double fTime = (fNumber - floor( fNumber )) * 86400.0;
fTime = ::rtl::math::round( fTime, int(nFirstRounding) ); fTime = ::rtl::math::round( fTime, int(nFirstRounding) );