[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sc/qa sc/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Wed Jun 19 10:55:25 UTC 2019


 sc/qa/unit/data/xlsx/pivottable_1s_difference.xlsx |binary
 sc/qa/unit/pivottable_filters_test.cxx             |   38 +++++++++++++++++++++
 sc/source/filter/excel/xepivotxml.cxx              |    6 ++-
 3 files changed, 42 insertions(+), 2 deletions(-)

New commits:
commit e6dd66b7d503910bffddcf59c8dcb801773c152e
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Wed May 1 07:22:44 2019 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Jun 19 12:54:48 2019 +0200

    tdf#125055: properly round fractions of seconds
    
    ... so that 2017-07-10T09:11:02.999999... becomes 2017-07-10T09:11:03,
    not 2017-07-10T09:11:02. The latter created duplicated items in pivot
    table cache previously.
    
    TODO: check what to do if the times are actually different by 100 ns?
    What Excel does then? Should we increase cache item precision?
    
    Change-Id: I622d1c784ee9fddf6b387bec2d8af87bae5668ba
    Reviewed-on: https://gerrit.libreoffice.org/71610
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    (cherry picked from commit f8472069d451ec001e602bbc5329ad030fae1219)
    Reviewed-on: https://gerrit.libreoffice.org/74350
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sc/qa/unit/data/xlsx/pivottable_1s_difference.xlsx b/sc/qa/unit/data/xlsx/pivottable_1s_difference.xlsx
new file mode 100644
index 000000000000..de8906cf94ca
Binary files /dev/null and b/sc/qa/unit/data/xlsx/pivottable_1s_difference.xlsx differ
diff --git a/sc/qa/unit/pivottable_filters_test.cxx b/sc/qa/unit/pivottable_filters_test.cxx
index 5570d9b1fc52..7fd27759f9e2 100644
--- a/sc/qa/unit/pivottable_filters_test.cxx
+++ b/sc/qa/unit/pivottable_filters_test.cxx
@@ -95,6 +95,7 @@ public:
     void testTdf124810();
     void testTdf124883();
     void testTdf125046();
+    void testTdf125055();
 
     CPPUNIT_TEST_SUITE(ScPivotTableFiltersTest);
 
@@ -144,6 +145,7 @@ public:
     CPPUNIT_TEST(testTdf124810);
     CPPUNIT_TEST(testTdf124883);
     CPPUNIT_TEST(testTdf125046);
+    CPPUNIT_TEST(testTdf125055);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -2635,6 +2637,42 @@ void ScPivotTableFiltersTest::testTdf125046()
                 "longText", "1");
 }
 
+void ScPivotTableFiltersTest::testTdf125055()
+{
+    ScDocShellRef xDocSh = loadDoc("pivottable_1s_difference.", FORMAT_XLSX);
+    CPPUNIT_ASSERT(xDocSh.is());
+
+    xmlDocPtr pDoc = XPathHelper::parseExport2(
+        *this, *xDocSh, m_xSFactory, "xl/pivotCache/pivotCacheDefinition1.xml", FORMAT_XLSX);
+    CPPUNIT_ASSERT(pDoc);
+
+    // 1-second precision should not result in duplicated entries for values different by ~1 s.
+    // Previously truncating nanoseconds in GetExcelFormattedDate converted
+    // "2017-07-10T09:11:02.99999..." into "2017-07-10T09:11:02", creating two identical strings
+    // Only compare times here: see comment to ScPivotTableFiltersTest::testPivotCacheExportXLSX
+    // "TODO Date generator in tests are one day higher, than during standard xlsx export"
+    OUString sISODateTime = getXPath(
+        pDoc, "/x:pivotCacheDefinition/x:cacheFields/x:cacheField[2]/x:sharedItems", "minDate");
+    CPPUNIT_ASSERT_EQUAL(OUString("T09:11:02"), sISODateTime.copy(10));
+    sISODateTime = getXPath(
+        pDoc, "/x:pivotCacheDefinition/x:cacheFields/x:cacheField[2]/x:sharedItems", "maxDate");
+    CPPUNIT_ASSERT_EQUAL(OUString("T09:11:03"), sISODateTime.copy(10));
+    assertXPath(pDoc, "/x:pivotCacheDefinition/x:cacheFields/x:cacheField[2]/x:sharedItems",
+                "count", "3");
+    assertXPathChildren(pDoc, "/x:pivotCacheDefinition/x:cacheFields/x:cacheField[2]/x:sharedItems",
+                        3); // 2 different values + empty
+    sISODateTime = getXPath(
+        pDoc, "/x:pivotCacheDefinition/x:cacheFields/x:cacheField[2]/x:sharedItems/x:d[1]", "v");
+    CPPUNIT_ASSERT_EQUAL(OUString("T09:11:02"), sISODateTime.copy(10));
+    sISODateTime = getXPath(
+        pDoc, "/x:pivotCacheDefinition/x:cacheFields/x:cacheField[2]/x:sharedItems/x:d[2]", "v");
+    CPPUNIT_ASSERT_EQUAL(OUString("T09:11:03"), sISODateTime.copy(10));
+    // Trailing empty
+    CPPUNIT_ASSERT_EQUAL(
+        2, getXPathPosition(
+               pDoc, "/x:pivotCacheDefinition/x:cacheFields/x:cacheField[2]/x:sharedItems", "m"));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(ScPivotTableFiltersTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/excel/xepivotxml.cxx b/sc/source/filter/excel/xepivotxml.cxx
index 147658d8fafc..280cb1a82a2b 100644
--- a/sc/source/filter/excel/xepivotxml.cxx
+++ b/sc/source/filter/excel/xepivotxml.cxx
@@ -197,8 +197,10 @@ namespace {
  */
 OUString GetExcelFormattedDate( double fSerialDateTime, const SvNumberFormatter& rFormatter )
 {
-    //::sax::Converter::convertDateTime(sBuf, (DateTime(rFormatter.GetNullDate()) + fSerialDateTime).GetUNODateTime(), 0, true);
-    css::util::DateTime aUDateTime = (DateTime(rFormatter.GetNullDate()) + fSerialDateTime).GetUNODateTime();
+    // tdf#125055: properly round the value to seconds when truncating nanoseconds below
+    constexpr double fHalfSecond = 1 / 86400.0 * 0.5;
+    css::util::DateTime aUDateTime
+        = (DateTime(rFormatter.GetNullDate()) + fSerialDateTime + fHalfSecond).GetUNODateTime();
     // We need to reset nanoseconds, to avoid string like: "1982-02-18T16:04:47.999999849"
     aUDateTime.NanoSeconds = 0;
     OUStringBuffer sBuf;


More information about the Libreoffice-commits mailing list