sc/qa/unit/data/functions/fods/datedif.fods |   31 ++++++++++++++++++++++++++--
 sc/source/core/tool/interpr2.cxx            |   11 +++------
 2 files changed, 33 insertions(+), 9 deletions(-)

New commits:
commit 4b605ca21b15ff4cbd734291e21ab02c5e57c424
Author: Winfried Donkers <[email protected]>
Date:   Sun Jan 29 15:58:05 2017 +0100

    tdf#105548 fix incorrect DATEDIF result.
    
    DATEDIF didn't convert datetime values to date before calculating
    date differences, which in certain cases produced incorrect results.
    Adding use case to unit test document.
    Removed 'TODO-comment' after checking what Excel really does.
    
    Change-Id: Icc16413e43f664d1c993d24e31eb4dc6990623e9
    Reviewed-on: https://gerrit.libreoffice.org/33662
    Tested-by: Jenkins <[email protected]>
    Reviewed-by: Eike Rathke <[email protected]>
    (cherry picked from commit e7606f1f19b2970f0160075f56d4d97029f1e47a)
    Reviewed-on: https://gerrit.libreoffice.org/33704

diff --git a/sc/qa/unit/data/functions/fods/datedif.fods 
b/sc/qa/unit/data/functions/fods/datedif.fods
index 9f13e96..9b09a9b 100644
--- a/sc/qa/unit/data/functions/fods/datedif.fods
+++ b/sc/qa/unit/data/functions/fods/datedif.fods
@@ -2610,6 +2610,33 @@
      </table:table-cell>
      <table:table-cell table:number-columns-repeated="8"/>
     </table:table-row>
+    <table:table-row table:style-name="ro5">
+     <table:table-cell table:formula="of:=DATEDIF([.F112];[.G112];[.H112])" 
office:value-type="float" office:value="2" calcext:value-type="float">
+      <text:p>2</text:p>
+     </table:table-cell>
+     <table:table-cell office:value-type="float" office:value="2" 
calcext:value-type="float">
+      <text:p>2</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="ce11" 
table:formula="of:=[.A112]=[.B112]" office:value-type="boolean" 
office:boolean-value="true" calcext:value-type="boolean">
+      <text:p>PRAVDA</text:p>
+     </table:table-cell>
+     <table:table-cell table:formula="of:=FORMULA([.A112])" 
office:value-type="string" office:string-value="=DATEDIF(F112;G112;H112)" 
calcext:value-type="string">
+      <text:p>=DATEDIF(F112;G112;H112)</text:p>
+     </table:table-cell>
+     <table:table-cell office:value-type="string" calcext:value-type="string">
+      <text:p>tdf#105548</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="ce40" office:value-type="date" 
office:date-value="2017-01-01T08:00:00" calcext:value-type="date">
+      <text:p>01/01/2017 08:00  AM</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="ce40" office:value-type="date" 
office:date-value="2017-01-03T07:00:00" calcext:value-type="date">
+      <text:p>01/03/17 07:00 AM</text:p>
+     </table:table-cell>
+     <table:table-cell office:value-type="string" calcext:value-type="string">
+      <text:p>d</text:p>
+     </table:table-cell>
+     <table:table-cell table:number-columns-repeated="8"/>
+    </table:table-row>
     <table:table-row table:style-name="ro6" 
table:number-rows-repeated="1048464">
      <table:table-cell table:number-columns-repeated="16"/>
     </table:table-row>
@@ -2617,7 +2644,7 @@
      <table:table-cell table:number-columns-repeated="16"/>
     </table:table-row>
     <calcext:conditional-formats>
-     <calcext:conditional-format 
calcext:target-range-address="Sheet2.C2:Sheet2.C111">
+     <calcext:conditional-format 
calcext:target-range-address="Sheet2.C2:Sheet2.C112">
       <calcext:condition calcext:apply-style-name="1true" 
calcext:value="=TRUE()" calcext:base-cell-address="Sheet2.C2"/>
       <calcext:condition calcext:apply-style-name="0false" 
calcext:value="!=TRUE()" calcext:base-cell-address="Sheet2.C2"/>
      </calcext:conditional-format>
@@ -2643,4 +2670,4 @@
    </table:named-expressions>
   </office:spreadsheet>
  </office:body>
-</office:document>
\ No newline at end of file
+</office:document>
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 59e87b7..c406233 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -783,8 +783,8 @@ void ScInterpreter::ScGetDateDif()
     if ( MustHaveParamCount( GetByte(), 3 ) )
     {
         OUString aInterval = GetString().getString();
-        double nDate2    = GetDouble();
-        double nDate1    = GetDouble();
+        long nDate2 = ::rtl::math::approxFloor( GetDouble() );
+        long nDate1 = ::rtl::math::approxFloor( GetDouble() );
 
         if (nGlobalError != FormulaError::NONE)
         {
@@ -811,12 +811,12 @@ void ScInterpreter::ScGetDateDif()
         sal_uInt16 d1, m1, d2, m2;
         sal_Int16 y1, y2;
         Date aDate1( *( pFormatter->GetNullDate()));
-        aDate1 += (long) ::rtl::math::approxFloor( nDate1 );
+        aDate1 += nDate1;
         y1 = aDate1.GetYear();
         m1 = aDate1.GetMonth();
         d1 = aDate1.GetDay();
         Date aDate2( *( pFormatter->GetNullDate()));
-        aDate2 += (long) ::rtl::math::approxFloor( nDate2 );
+        aDate2 += nDate2;
         y2 = aDate2.GetYear();
         m2 = aDate2.GetMonth();
         d2 = aDate2.GetDay();
@@ -905,9 +905,6 @@ void ScInterpreter::ScGetDateDif()
         {
             // Return number of days, excluding years.
 
-            /* TODO: check what Excel really does, though this seems to be
-             * reasonable */
-
             // Condition corresponds with "y".
             if (m2 > m1 || (m2 == m1 && d2 >= d1))
                 aDate1.SetYear( y2 );
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to