include/tools/duration.hxx       |    8 +++++++-
 sc/source/core/tool/interpr5.cxx |    9 +++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

New commits:
commit d646341e5ddc625d9cf69777b4be174aebb43700
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Mon Nov 13 16:26:05 2023 +0100
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Mon Nov 13 19:37:49 2023 +0100

    Related: tdf#125580 Use tools::Duration constexpr accuracy epsilon values
    
    Change-Id: I8f83c23206686ce23fb3f8be7d7098bbe252dc41
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159388
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/include/tools/duration.hxx b/include/tools/duration.hxx
index 9fae80d1d7c9..9f032539e142 100644
--- a/include/tools/duration.hxx
+++ b/include/tools/duration.hxx
@@ -31,8 +31,13 @@ public:
         minutes and seconds values here though. */
     Duration(const Time& rStart, const Time& rEnd);
 
+    constexpr static sal_uInt64 kAccuracyEpsilonNanoseconds = 300;
+    constexpr static sal_uInt64 kAccuracyEpsilonNanosecondsMicroseconds = 999;
+
     /** Difference in days, like DateTime()-DateTime().
 
+        Can also be used to round a date+time value to, for example, 
microseconds.
+
         @param  nAccuracyEpsilonNanoseconds
                 Round for example by 1 nanosecond if it's just 1 off to a
                 second,  i.e. 0999999999 or 0000000001. This can be loosened if
@@ -41,7 +46,8 @@ public:
                 accuracy epsilon (=unsharpness) of ~300 is required. Hence 
default.
                 Must be 0 <= nAccuracyEpsilonNanoseconds <= 
Time::nanoSecPerSec - 1.
      */
-    explicit Duration(double fTimeInDays, sal_uInt64 
nAccuracyEpsilonNanoseconds = 300);
+    explicit Duration(double fTimeInDays,
+                      sal_uInt64 nAccuracyEpsilonNanoseconds = 
kAccuracyEpsilonNanoseconds);
 
     /** Time can be a limited duration as well and can have out-of-range
         values, it will be normalized. Sign of both days and Time must be equal
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index 90015018eec6..ae499ec492d1 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -1344,7 +1344,9 @@ void ScInterpreter::CalculateAddSub(bool _bSub)
         {
             // Limit to microseconds resolution on date inflicted or duration
             // values of 24 hours or more.
-            const sal_uInt64 nEpsilon = ((std::fabs(fVal1) >= 1.0 || 
std::fabs(fVal2) >= 1.0) ? 999 : 300);
+            const sal_uInt64 nEpsilon = ((std::fabs(fVal1) >= 1.0 || 
std::fabs(fVal2) >= 1.0) ?
+                    ::tools::Duration::kAccuracyEpsilonNanosecondsMicroseconds 
:
+                    ::tools::Duration::kAccuracyEpsilonNanoseconds);
             if (_bSub)
                 PushDouble( ::tools::Duration( fVal1 - fVal2, 
nEpsilon).GetInDays());
             else
commit 007e9e46d936ad7631792188168dffec7051b27f
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Mon Nov 13 14:26:38 2023 +0100
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Mon Nov 13 19:37:35 2023 +0100

    Resolves: tdf#125580 Limit operator +|- date+time resolution to microseconds
    
    With tools::Duration that is now finally easily possible.
    
    Change-Id: Ib22e6f94d321be78578997bef5094284f2bd549b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159378
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Eike Rathke <er...@redhat.com>

diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index dcb5ee6ea343..90015018eec6 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -1342,10 +1342,13 @@ void ScInterpreter::CalculateAddSub(bool _bSub)
                 && ((_bSub && std::fabs(fVal1 - fVal2) <= SAL_MAX_INT32)
                     || (!_bSub && std::fabs(fVal1 + fVal2) <= SAL_MAX_INT32)))
         {
+            // Limit to microseconds resolution on date inflicted or duration
+            // values of 24 hours or more.
+            const sal_uInt64 nEpsilon = ((std::fabs(fVal1) >= 1.0 || 
std::fabs(fVal2) >= 1.0) ? 999 : 300);
             if (_bSub)
-                PushDouble( ::tools::Duration( fVal1 - fVal2).GetInDays());
+                PushDouble( ::tools::Duration( fVal1 - fVal2, 
nEpsilon).GetInDays());
             else
-                PushDouble( ::tools::Duration( fVal1 + fVal2).GetInDays());
+                PushDouble( ::tools::Duration( fVal1 + fVal2, 
nEpsilon).GetInDays());
         }
         else
         {

Reply via email to