sax/source/tools/converter.cxx                     |   18 --
 sc/qa/unit/data/functions/date_time/fods/time.fods |  169 ---------------------
 2 files changed, 13 insertions(+), 174 deletions(-)

New commits:
commit a03df92a0ca6ae04cb99bb9ab678e31d82363879
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Oct 8 02:08:00 2024 +0500
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Oct 21 12:45:22 2024 +0200

    tdf#163344: improve Converter::convertDuration
    
    Let it use the same calculation as ImpSvNumberInputScan::GetTimeRef.
    Decreases rounding errors.
    
    Change-Id: I6474a1a5913d78c236adc511389c4abcebed2de6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174650
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 9c9d2e21be06fa1c806c110812d6df783109d8b9)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174664
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx
index bc2342d5b508..990e31e20d4f 100644
--- a/sax/source/tools/converter.cxx
+++ b/sax/source/tools/converter.cxx
@@ -35,6 +35,7 @@
 #include <o3tl/unit_conversion.hxx>
 #include <osl/diagnose.h>
 #include <tools/long.hxx>
+#include <tools/time.hxx>
 
 #include <algorithm>
 #include <string_view>
@@ -976,16 +977,13 @@ static bool convertDurationHelper(double& rfTime, V pStr)
 
     if ( bSuccess )
     {
-        if ( nDays )
-            nHours += nDays * 24;               // add the days to the hours 
part
-        double fHour = nHours;
-        double fMin = nMins;
-        double fSec = nSecs;
-        double fFraction = o3tl::toDouble(sDoubleStr);
-        double fTempTime = fHour / 24;
-        fTempTime += fMin / (24 * 60);
-        fTempTime += fSec / (24 * 60 * 60);
-        fTempTime += fFraction / (24 * 60 * 60);
+        // Calculate similar to ImpSvNumberInputScan::GetTimeRef: first, sum 
whole seconds, add
+        // second fraction, and finally, divide. Produces less rounding errors 
than calculating
+        // fractions of a day from seconds, minutes, hours separately, and 
then adding together.
+        double seconds = nDays * tools::Time::secondPerDay + nHours * 
tools::Time::secondPerHour
+                         + nMins * tools::Time::secondPerMinute + nSecs
+                         + o3tl::toDouble(sDoubleStr);
+        double fTempTime = seconds / tools::Time::secondPerDay;
 
         // negative duration?
         if ( bIsNegativeDuration )
diff --git a/sc/qa/unit/data/functions/date_time/fods/time.fods 
b/sc/qa/unit/data/functions/date_time/fods/time.fods
index f2f2df5512a9..40e60f1271f0 100644
--- a/sc/qa/unit/data/functions/date_time/fods/time.fods
+++ b/sc/qa/unit/data/functions/date_time/fods/time.fods
@@ -748,9 +748,11 @@
      <table:table-cell table:number-columns-repeated="4"/>
     </table:table-row>
     <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="7"/>
+     <table:table-cell table:style-name="ce13" 
table:formula="of:=TIME(14;30;0)" office:value-type="time"/>
+     <table:table-cell table:style-name="ce16" office:value-type="time" 
office:time-value="PT14H30M00S"/>
+     <table:table-cell table:style-name="ce17" 
table:formula="of:=ORG.LIBREOFFICE.RAWSUBTRACT([.A11];[.B11])=0" 
office:value-type="boolean"/>
+     <table:table-cell table:style-name="ce21" 
table:formula="of:=FORMULA([.A11])" office:value-type="string"/>
+     <table:table-cell table:number-columns-repeated="6"/>
      <table:table-cell office:value-type="float" office:value="19" 
calcext:value-type="float">
       <text:p>19</text:p>
      </table:table-cell>
@@ -772,167 +774,6 @@
      <table:table-cell table:style-name="ce19"/>
      <table:table-cell table:number-columns-repeated="12"/>
     </table:table-row>
-    <table:table-row table:style-name="ro2" table:number-rows-repeated="2">
-     <table:table-cell table:style-name="ce14" 
table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce20"/>
-     <table:table-cell table:style-name="ce14" 
table:number-columns-repeated="2"/>
-     <table:table-cell table:number-columns-repeated="10"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:style-name="ce15" 
table:number-columns-repeated="5"/>
-     <table:table-cell table:number-columns-repeated="4"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="6"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:style-name="ce14" 
table:number-columns-repeated="5"/>
-     <table:table-cell table:number-columns-repeated="10"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:style-name="ce14" 
table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce20"/>
-     <table:table-cell table:style-name="ce14" 
table:number-columns-repeated="2"/>
-     <table:table-cell table:number-columns-repeated="10"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:style-name="ce14" 
table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce20"/>
-     <table:table-cell table:style-name="ce14" 
table:number-columns-repeated="2"/>
-     <table:table-cell table:number-columns-repeated="4"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="5"/>
-     <table:table-cell/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="6"/>
-     <table:table-cell table:style-name="ce24"/>
-     <table:table-cell table:number-columns-repeated="5"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="12"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="6"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="5"/>
-     <table:table-cell/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2" table:number-rows-repeated="2">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="12"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="6"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="5"/>
-     <table:table-cell/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2" table:number-rows-repeated="6">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="12"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="6"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="5"/>
-     <table:table-cell/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2" table:number-rows-repeated="4">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="12"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="6"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="5"/>
-     <table:table-cell/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2" table:number-rows-repeated="2">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="12"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="6"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="5"/>
-     <table:table-cell/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="12"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="15"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="9"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="5"/>
-     <table:table-cell/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2" table:number-rows-repeated="2">
-     <table:table-cell table:number-columns-repeated="15"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="9"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="5"/>
-     <table:table-cell/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2" table:number-rows-repeated="2">
-     <table:table-cell table:number-columns-repeated="15"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="9"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="5"/>
-     <table:table-cell/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2" table:number-rows-repeated="2">
-     <table:table-cell table:number-columns-repeated="15"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="9"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="5"/>
-     <table:table-cell/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2" table:number-rows-repeated="2">
-     <table:table-cell table:number-columns-repeated="15"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="9"/>
-     <table:table-cell table:style-name="ce22" 
table:number-columns-repeated="5"/>
-     <table:table-cell/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2" table:number-rows-repeated="2">
-     <table:table-cell table:number-columns-repeated="15"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="9"/>
-     <table:table-cell table:style-name="ce25" 
table:number-columns-repeated="5"/>
-     <table:table-cell table:style-name="ce26" office:value-type="string" 
calcext:value-type="string">
-      <text:p>Age</text:p>
-     </table:table-cell>
-    </table:table-row>
-    <table:table-row table:style-name="ro2" table:number-rows-repeated="2">
-     <table:table-cell table:number-columns-repeated="9"/>
-     <table:table-cell table:style-name="ce26" 
table:number-columns-repeated="6"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2" 
table:number-rows-repeated="1048515">
-     <table:table-cell table:number-columns-repeated="15"/>
-    </table:table-row>
-    <table:table-row table:style-name="ro2">
-     <table:table-cell table:number-columns-repeated="15"/>
-    </table:table-row>
     <calcext:conditional-formats>
      <calcext:conditional-format 
calcext:target-range-address="Sheet2.C18:Sheet2.C41 Sheet2.C2:Sheet2.C15">
       <calcext:condition calcext:apply-style-name="Default" 
calcext:value="=&quot;&quot;" calcext:base-cell-address="Sheet2.C2"/>

Reply via email to