[Libreoffice-commits] core.git: sc/qa sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Oct 8 14:39:54 UTC 2018
sc/qa/unit/datatransformation_test.cxx | 433 ++++++++++++++++-------
sc/source/ui/dataprovider/datatransformation.cxx | 247 +++++--------
2 files changed, 407 insertions(+), 273 deletions(-)
New commits:
commit 4a00c79aafc6dde331cf4bb351d98226a9337171
Author: Vikas Mahato <vikasmahato0 at gmail.com>
AuthorDate: Tue Aug 21 23:58:58 2018 +0530
Commit: Eike Rathke <erack at redhat.com>
CommitDate: Mon Oct 8 16:39:31 2018 +0200
Added date time transformations - follow-up
Change-Id: I130feda7c835b067a542736ad6fadc79cabc4f41
Reviewed-on: https://gerrit.libreoffice.org/59413
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack at redhat.com>
diff --git a/sc/qa/unit/datatransformation_test.cxx b/sc/qa/unit/datatransformation_test.cxx
index 97a8e49c79d8..f1aba85b82bc 100644
--- a/sc/qa/unit/datatransformation_test.cxx
+++ b/sc/qa/unit/datatransformation_test.cxx
@@ -16,7 +16,8 @@
#include <dataprovider.hxx>
#include <datatransformation.hxx>
#include <vcl/scheduler.hxx>
-
+#include <tools/datetime.hxx>
+#include <tools/time.hxx>
#include <memory>
class ScDataTransformationTest : public ScBootstrapFixture
@@ -543,269 +544,440 @@ void ScDataTransformationTest::testReplaceNull()
void ScDataTransformationTest::testGetDateString()
{
- m_pDoc->SetValue(2, 0, 0, 43248.5624189815);
- m_pDoc->SetValue(2, 1, 0, 42941.5624189815);
- m_pDoc->SetValue(2, 2, 0, 42518.5624189815);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DATE_STRING );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_EQUAL(OUString("05/28/18"), m_pDoc->GetString(2, 0, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("07/25/17"), m_pDoc->GetString(2, 1, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("05/28/16"), m_pDoc->GetString(2, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("01/25/11"), m_pDoc->GetString(2, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("10/12/94"), m_pDoc->GetString(2, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("09/23/96"), m_pDoc->GetString(2, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("08/15/47"), m_pDoc->GetString(2, 3, 0));
}
void ScDataTransformationTest::testGetYear()
{
- m_pDoc->SetValue(2, 0, 0, 20);
- m_pDoc->SetValue(2, 1, 0, 3342.44);
- m_pDoc->SetValue(2, 2, 0, 955.05);
- m_pDoc->SetValue(2, 3, 0, 4890.22);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::YEAR );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(1900, m_pDoc->GetValue(2, 0, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(1909, m_pDoc->GetValue(2, 1, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(1902, m_pDoc->GetValue(2, 2, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(1913, m_pDoc->GetValue(2, 3, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2011, m_pDoc->GetValue(2, 0, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1994, m_pDoc->GetValue(2, 1, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1996, m_pDoc->GetValue(2, 2, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1947, m_pDoc->GetValue(2, 3, 0), 0);
}
void ScDataTransformationTest::testGetStartOfYear()
{
- m_pDoc->SetValue(2, 0, 0, 43248.5624189815);
- m_pDoc->SetValue(2, 1, 0, 42941.5624189815);
- m_pDoc->SetValue(2, 2, 0, 42518.5624189815);
- m_pDoc->SetValue(2, 3, 0, 44217.5624189815);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::START_OF_YEAR );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_EQUAL(OUString("01/01/18"), m_pDoc->GetString(2, 0, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("01/01/17"), m_pDoc->GetString(2, 1, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("01/01/16"), m_pDoc->GetString(2, 2, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("01/01/21"), m_pDoc->GetString(2, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("01/01/11"), m_pDoc->GetString(2, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("01/01/94"), m_pDoc->GetString(2, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("01/01/96"), m_pDoc->GetString(2, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("01/01/47"), m_pDoc->GetString(2, 3, 0));
}
void ScDataTransformationTest::testGetEndOfYear()
{
- m_pDoc->SetValue(2, 0, 0, 43248.5624189815);
- m_pDoc->SetValue(2, 1, 0, 42941.5624189815);
- m_pDoc->SetValue(2, 2, 0, 42518.5624189815);
- m_pDoc->SetValue(2, 3, 0, 44217.5624189815);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::END_OF_YEAR );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_EQUAL(OUString("12/31/18"), m_pDoc->GetString(2, 0, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("12/31/17"), m_pDoc->GetString(2, 1, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("12/31/16"), m_pDoc->GetString(2, 2, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("12/31/21"), m_pDoc->GetString(2, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("12/31/11"), m_pDoc->GetString(2, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("12/31/94"), m_pDoc->GetString(2, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("12/31/96"), m_pDoc->GetString(2, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("12/31/47"), m_pDoc->GetString(2, 3, 0));
}
void ScDataTransformationTest::testGetMonth()
{
- m_pDoc->SetValue(2, 0, 0, 20);
- m_pDoc->SetValue(2, 1, 0, 3342.44);
- m_pDoc->SetValue(2, 2, 0, 955.05);
- m_pDoc->SetValue(2, 3, 0, 4890.22);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::MONTH );
aTransform.Transform(*m_pDoc);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1, m_pDoc->GetValue(2, 0, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(2, m_pDoc->GetValue(2, 1, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(8, m_pDoc->GetValue(2, 2, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(5, m_pDoc->GetValue(2, 3, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(10, m_pDoc->GetValue(2, 1, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(9, m_pDoc->GetValue(2, 2, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8, m_pDoc->GetValue(2, 3, 0), 0);
}
void ScDataTransformationTest::testGetMonthName()
{
- m_pDoc->SetValue(2, 0, 0, 20);
- m_pDoc->SetValue(2, 1, 0, 3342.44);
- m_pDoc->SetValue(2, 2, 0, 955.05);
- m_pDoc->SetValue(2, 3, 0, 4890.22);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::MONTH_NAME);
aTransform.Transform(*m_pDoc);
CPPUNIT_ASSERT_EQUAL(OUString("January"), m_pDoc->GetString(2, 0, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("February"), m_pDoc->GetString(2, 1, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("August"), m_pDoc->GetString(2, 2, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("May"), m_pDoc->GetString(2, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("October"), m_pDoc->GetString(2, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("September"), m_pDoc->GetString(2, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("August"), m_pDoc->GetString(2, 3, 0));
}
void ScDataTransformationTest::testGetStartOfMonth()
{
- m_pDoc->SetValue(2, 0, 0, 43248.5624189815);
- m_pDoc->SetValue(2, 1, 0, 42941.562418981);
- m_pDoc->SetValue(2, 2, 0, 42518.5624189815);
- m_pDoc->SetValue(2, 3, 0, 44217.5624189815);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::START_OF_MONTH );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_EQUAL(OUString("05/01/18"), m_pDoc->GetString(2, 0, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("07/01/17"), m_pDoc->GetString(2, 1, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("05/01/16"), m_pDoc->GetString(2, 2, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("01/01/21"), m_pDoc->GetString(2, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("01/01/11"), m_pDoc->GetString(2, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("10/01/94"), m_pDoc->GetString(2, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("09/01/96"), m_pDoc->GetString(2, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("08/01/47"), m_pDoc->GetString(2, 3, 0));
}
void ScDataTransformationTest::testGetEndOfMonth()
{
- m_pDoc->SetValue(2, 0, 0, 43248.5624189815);
- m_pDoc->SetValue(2, 1, 0, 42941.5624189815);
- m_pDoc->SetValue(2, 2, 0, 42518.5624189815);
- m_pDoc->SetValue(2, 3, 0, 44217.5624189815);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::END_OF_MONTH );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_EQUAL(OUString("05/31/18"), m_pDoc->GetString(2, 0, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("07/31/17"), m_pDoc->GetString(2, 1, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("05/31/16"), m_pDoc->GetString(2, 2, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("01/31/21"), m_pDoc->GetString(2, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("01/31/11"), m_pDoc->GetString(2, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("10/31/94"), m_pDoc->GetString(2, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("09/30/96"), m_pDoc->GetString(2, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("08/31/47"), m_pDoc->GetString(2, 3, 0));
}
void ScDataTransformationTest::testGetDay()
{
- m_pDoc->SetValue(2, 0, 0, 20);
- m_pDoc->SetValue(2, 1, 0, 3342.44);
- m_pDoc->SetValue(2, 2, 0, 955.05);
- m_pDoc->SetValue(2, 3, 0, 4890.22);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DAY );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(20, m_pDoc->GetValue(2, 0, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(24, m_pDoc->GetValue(2, 1, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(13, m_pDoc->GetValue(2, 2, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(22, m_pDoc->GetValue(2, 3, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(25, m_pDoc->GetValue(2, 0, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(12, m_pDoc->GetValue(2, 1, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(23, m_pDoc->GetValue(2, 2, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(15, m_pDoc->GetValue(2, 3, 0), 0);
}
void ScDataTransformationTest::testGetDayOfWeek()
{
- m_pDoc->SetValue(2, 0, 0, 20);
- m_pDoc->SetValue(2, 1, 0, 3342.44);
- m_pDoc->SetValue(2, 2, 0, 955.05);
- m_pDoc->SetValue(2, 3, 0, 4890.22);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_WEEK );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(5, m_pDoc->GetValue(2, 0, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1, m_pDoc->GetValue(2, 0, 0), 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(2, m_pDoc->GetValue(2, 1, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(2, m_pDoc->GetValue(2, 2, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(3, m_pDoc->GetValue(2, 3, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0, m_pDoc->GetValue(2, 2, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4, m_pDoc->GetValue(2, 3, 0), 0);
}
void ScDataTransformationTest::testGetDayOfYear()
{
- m_pDoc->SetValue(2, 0, 0, 20);
- m_pDoc->SetValue(2, 1, 0, 3342.44);
- m_pDoc->SetValue(2, 2, 0, 955.05);
- m_pDoc->SetValue(2, 3, 0, 4890.22);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_YEAR );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(20, m_pDoc->GetValue(2, 0, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(55, m_pDoc->GetValue(2, 1, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(225, m_pDoc->GetValue(2, 2, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(142, m_pDoc->GetValue(2, 3, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(25, m_pDoc->GetValue(2, 0, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(285, m_pDoc->GetValue(2, 1, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(267, m_pDoc->GetValue(2, 2, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(227, m_pDoc->GetValue(2, 3, 0), 0);
}
void ScDataTransformationTest::testGetQuarter()
{
- m_pDoc->SetValue(2, 0, 0, 20);
- m_pDoc->SetValue(2, 1, 0, 3342.44);
- m_pDoc->SetValue(2, 2, 0, 955.05);
- m_pDoc->SetValue(2, 3, 0, 4890.22);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::QUARTER );
aTransform.Transform(*m_pDoc);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1, m_pDoc->GetValue(2, 0, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(1, m_pDoc->GetValue(2, 1, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4, m_pDoc->GetValue(2, 1, 0), 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(3, m_pDoc->GetValue(2, 2, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(2, m_pDoc->GetValue(2, 3, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(3, m_pDoc->GetValue(2, 3, 0), 0);
}
void ScDataTransformationTest::testGetStartOfQuarter()
{
- m_pDoc->SetValue(2, 0, 0, 43148.5624189815);
- m_pDoc->SetValue(2, 1, 0, 43264.3055555556);
- m_pDoc->SetValue(2, 2, 0, 43306.4946990741);
- m_pDoc->SetValue(2, 3, 0, 43406.4946990741);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::START_OF_QUARTER );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_EQUAL(OUString("01/01/18"), m_pDoc->GetString(2, 0, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("04/01/18"), m_pDoc->GetString(2, 1, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("07/01/18"), m_pDoc->GetString(2, 2, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("10/01/18"), m_pDoc->GetString(2, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("01/01/11"), m_pDoc->GetString(2, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("10/01/94"), m_pDoc->GetString(2, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("07/01/96"), m_pDoc->GetString(2, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("07/01/47"), m_pDoc->GetString(2, 3, 0));
}
void ScDataTransformationTest::testGetEndOfQuarter()
{
- m_pDoc->SetValue(2, 0, 0, 43148.5624189815);
- m_pDoc->SetValue(2, 1, 0, 43264.3055555556);
- m_pDoc->SetValue(2, 2, 0, 43306.4946990741);
- m_pDoc->SetValue(2, 3, 0, 43406.4946990741);
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ css::util::Date aDate1(25,1,2011);
+ css::util::Date aDate2(12,10,1994);
+ css::util::Date aDate3(23,9,1996);
+ css::util::Date aDate4(15,8,1947);
+
+ double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
+ double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
+ double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
+ double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
+
+ m_pDoc->SetValue(2, 0, 0, nDate1);
+ m_pDoc->SetValue(2, 1, 0, nDate2);
+ m_pDoc->SetValue(2, 2, 0, nDate3);
+ m_pDoc->SetValue(2, 3, 0, nDate4);
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::END_OF_QUARTER );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_EQUAL(OUString("03/31/18"), m_pDoc->GetString(2, 0, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("06/30/18"), m_pDoc->GetString(2, 1, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("09/30/18"), m_pDoc->GetString(2, 2, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("12/31/18"), m_pDoc->GetString(2, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("03/31/11"), m_pDoc->GetString(2, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("12/31/94"), m_pDoc->GetString(2, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("09/30/96"), m_pDoc->GetString(2, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("09/30/47"), m_pDoc->GetString(2, 3, 0));
}
void ScDataTransformationTest::testGetTime()
{
- m_pDoc->SetValue(2, 0, 0, 20.562419);
- m_pDoc->SetValue(2, 1, 0, 43249.3077546296);
- m_pDoc->SetValue(2, 2, 0, 43249.3990740741);
- m_pDoc->SetValue(2, 3, 0, 43249.4234837963);
+ tools::Time aTime1(5,30,12);
+ tools::Time aTime2(7,23,9);
+ tools::Time aTime3(9,34,40);
+ tools::Time aTime4(22,9,49);
+
+ m_pDoc->SetValue(2, 0, 0, aTime1.GetTimeInDays());
+ m_pDoc->SetValue(2, 1, 0, aTime2.GetTimeInDays());
+ m_pDoc->SetValue(2, 2, 0, aTime3.GetTimeInDays());
+ m_pDoc->SetValue(2, 3, 0, aTime4.GetTimeInDays());
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::TIME );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_EQUAL(OUString("01:29:53 PM"), m_pDoc->GetString(2, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("05:30:12 AM"), m_pDoc->GetString(2, 0, 0));
CPPUNIT_ASSERT_EQUAL(OUString("07:23:09 AM"), m_pDoc->GetString(2, 1, 0));
CPPUNIT_ASSERT_EQUAL(OUString("09:34:40 AM"), m_pDoc->GetString(2, 2, 0));
- CPPUNIT_ASSERT_EQUAL(OUString("10:09:49 AM"), m_pDoc->GetString(2, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("10:09:49 PM"), m_pDoc->GetString(2, 3, 0));
}
void ScDataTransformationTest::testGetHour()
{
- m_pDoc->SetValue(2, 0, 0, 20.562419);
- m_pDoc->SetValue(2, 1, 0, 43249.3077546296);
- m_pDoc->SetValue(2, 2, 0, 43249.3990740741);
- m_pDoc->SetValue(2, 3, 0, 43249.4234837963);
+ tools::Time aTime1(5,30,12);
+ tools::Time aTime2(7,23,9);
+ tools::Time aTime3(9,34,40);
+ tools::Time aTime4(22,9,49);
+
+ m_pDoc->SetValue(2, 0, 0, aTime1.GetTimeInDays());
+ m_pDoc->SetValue(2, 1, 0, aTime2.GetTimeInDays());
+ m_pDoc->SetValue(2, 2, 0, aTime3.GetTimeInDays());
+ m_pDoc->SetValue(2, 3, 0, aTime4.GetTimeInDays());
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::HOUR );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(13, m_pDoc->GetValue(2, 0, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(5, m_pDoc->GetValue(2, 0, 0), 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(7, m_pDoc->GetValue(2, 1, 0), 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(9, m_pDoc->GetValue(2, 2, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(10, m_pDoc->GetValue(2, 3, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(22, m_pDoc->GetValue(2, 3, 0), 0);
}
void ScDataTransformationTest::testGetMinute()
{
- m_pDoc->SetValue(2, 0, 0, 20.562419);
- m_pDoc->SetValue(2, 1, 0, 43249.3077546296);
- m_pDoc->SetValue(2, 2, 0, 43249.3990740741);
- m_pDoc->SetValue(2, 3, 0, 43249.4234837963);
+ tools::Time aTime1(5,30,12);
+ tools::Time aTime2(7,23,9);
+ tools::Time aTime3(9,34,40);
+ tools::Time aTime4(22,9,49);
+
+ m_pDoc->SetValue(2, 0, 0, aTime1.GetTimeInDays());
+ m_pDoc->SetValue(2, 1, 0, aTime2.GetTimeInDays());
+ m_pDoc->SetValue(2, 2, 0, aTime3.GetTimeInDays());
+ m_pDoc->SetValue(2, 3, 0, aTime4.GetTimeInDays());
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::MINUTE );
aTransform.Transform(*m_pDoc);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(29, m_pDoc->GetValue(2, 0, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(30, m_pDoc->GetValue(2, 0, 0), 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(23, m_pDoc->GetValue(2, 1, 0), 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(34, m_pDoc->GetValue(2, 2, 0), 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(9, m_pDoc->GetValue(2, 3, 0), 0);
@@ -813,16 +985,21 @@ void ScDataTransformationTest::testGetMinute()
void ScDataTransformationTest::testGetSecond()
{
- m_pDoc->SetValue(2, 0, 0, 20.562419);
- m_pDoc->SetValue(2, 1, 0, 43249.3077546296);
- m_pDoc->SetValue(2, 2, 0, 43249.3990740741);
- m_pDoc->SetValue(2, 3, 0, 43249.4234837963);
+ tools::Time aTime1(5,30,53);
+ tools::Time aTime2(7,23,10);
+ tools::Time aTime3(9,34,40);
+ tools::Time aTime4(22,9,49);
+
+ m_pDoc->SetValue(2, 0, 0, aTime1.GetTimeInDays());
+ m_pDoc->SetValue(2, 1, 0, aTime2.GetTimeInDays());
+ m_pDoc->SetValue(2, 2, 0, aTime3.GetTimeInDays());
+ m_pDoc->SetValue(2, 3, 0, aTime4.GetTimeInDays());
sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::SECOND );
aTransform.Transform(*m_pDoc);
CPPUNIT_ASSERT_DOUBLES_EQUAL(53, m_pDoc->GetValue(2, 0, 0), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(9, m_pDoc->GetValue(2, 1, 0), 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(10, m_pDoc->GetValue(2, 1, 0), 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(40, m_pDoc->GetValue(2, 2, 0), 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(49, m_pDoc->GetValue(2, 3, 0), 0);
}
diff --git a/sc/source/ui/dataprovider/datatransformation.cxx b/sc/source/ui/dataprovider/datatransformation.cxx
index 0c4e64a83f3e..4295e63d2bf7 100644
--- a/sc/source/ui/dataprovider/datatransformation.cxx
+++ b/sc/source/ui/dataprovider/datatransformation.cxx
@@ -14,63 +14,16 @@
#include <cmath>
#include <tools/datetime.hxx>
#include <svl/zforlist.hxx>
-namespace {
-
-int getHour(double nDateTime)
-{
- long nDays = std::trunc(nDateTime);
- double nTime = nDateTime - nDays;
- return std::trunc(nTime*24);
-}
-
-int getMinute(double nDateTime)
-{
- long nDays = std::trunc(nDateTime);
- double nTime = nDateTime - nDays;
- nTime = nTime*24;
- nTime = nTime - std::trunc(nTime);
- return std::trunc(nTime*60);
-}
-
-int getSecond(double nDateTime)
-{
- double nDays = std::trunc(nDateTime);
- double nTime = nDateTime - nDays;
- nTime = nTime*24;
- nTime = nTime - std::trunc(nTime);
- nTime = nTime*60;
- nTime = nTime - std::trunc(nTime);
- return std::trunc(nTime*60);
-}
+#include <globalnames.hxx>
-OUString getTwoDigitString(OUString sString)
-{
- if(sString.getLength() == 1)
- sString = "0" + sString;
- return sString;
-}
+namespace {
-DateTime getDate(double nDateTime, SvNumberFormatter* pFormatter)
+Date getDate(double nDateTime, SvNumberFormatter* pFormatter)
{
- sal_Int32 nDays = std::trunc(nDateTime);
- Date aDate = pFormatter->GetNullDate();
- aDate.AddDays(nDays + 1);
+ Date aDate = pFormatter->GetNullDate();
+ aDate.AddDays(static_cast<sal_Int32>(::rtl::math::approxFloor(nDateTime)));
return aDate;
}
-
-OUString getTimeString(double nDateTime)
-{
- OUString sHour = OUString::number(getHour(nDateTime));
- sHour = getTwoDigitString(sHour);
-
- OUString sMinute = OUString::number(getMinute(nDateTime));
- sMinute = getTwoDigitString(sMinute);
-
- OUString sSecond = OUString::number(getSecond(nDateTime));
- sSecond = getTwoDigitString(sSecond);
-
- return sHour + ":" + sMinute + ":" + sSecond;
-}
}
namespace sc {
@@ -781,20 +734,17 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
{
case DATETIME_TRANSFORMATION_TYPE::DATE_STRING:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
+ SvNumFormatType nFormatType = SvNumFormatType::DATE;
+ LanguageType eLanguage = ScGlobal::eLnge;
+ sal_uInt32 nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
rDoc.GetCellType(rCol, nRow, 0, eType);
if (eType == CELLTYPE_VALUE)
{
- double nVal = rDoc.GetValue(rCol, nRow, 0);
-
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
- SvNumFormatType nFormatType = SvNumFormatType::DATE;
- LanguageType eLanguage = ScGlobal::eLnge;
ScAddress aAddress(rCol, nRow, 0);
- sal_uLong nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
- rDoc.SetValue(rCol, nRow, 0, nVal);
rDoc.SetNumberFormat(aAddress, nFormat);
}
}
@@ -802,6 +752,7 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::YEAR:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
@@ -809,7 +760,6 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
Date aDate = getDate(nVal, pFormatter);
rDoc.SetValue(rCol, nRow, 0, aDate.GetYear());
}
@@ -818,6 +768,10 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::START_OF_YEAR:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
+ SvNumFormatType nFormatType = SvNumFormatType::DATE;
+ LanguageType eLanguage = ScGlobal::eLnge;
+ sal_uInt32 nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
@@ -825,17 +779,12 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
-
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
Date aDate = getDate(nVal, pFormatter);
- nVal -= aDate.GetDayOfYear() - 2;
- nVal = std::trunc(nVal);
- SvNumFormatType nFormatType = SvNumFormatType::DATE;
- LanguageType eLanguage = ScGlobal::eLnge;
- ScAddress aAddress(rCol, nRow, 0);
- sal_uLong nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
+ aDate.SetDay(1);
+ aDate.SetMonth(1);
+ nVal = aDate - pFormatter->GetNullDate();
+ ScAddress aAddress(rCol, nRow, 0);
rDoc.SetValue(rCol, nRow, 0, nVal);
-
rDoc.SetNumberFormat(aAddress, nFormat);
}
}
@@ -843,6 +792,11 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::END_OF_YEAR:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
+ SvNumFormatType nFormatType = SvNumFormatType::DATE;
+ LanguageType eLanguage = ScGlobal::eLnge;
+ sal_uInt32 nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
+
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
@@ -850,17 +804,12 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
-
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
Date aDate = getDate(nVal, pFormatter);
- nVal += ( aDate.GetDaysInYear() - aDate.GetDayOfYear() + 1);
- nVal = std::trunc(nVal);
- SvNumFormatType nFormatType = SvNumFormatType::DATE;
- LanguageType eLanguage = ScGlobal::eLnge;
+ aDate.SetMonth(12);
+ aDate.SetDay(31);
+ nVal = aDate - pFormatter->GetNullDate();
ScAddress aAddress(rCol, nRow, 0);
- sal_uLong nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
rDoc.SetValue(rCol, nRow, 0, nVal);
-
rDoc.SetNumberFormat(aAddress, nFormat);
}
}
@@ -868,6 +817,7 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::MONTH:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
@@ -875,7 +825,6 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
Date aDate = getDate(nVal, pFormatter);
rDoc.SetValue(rCol, nRow, 0, aDate.GetMonth());
}
@@ -884,25 +833,29 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::MONTH_NAME:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
+ LanguageType eLanguage = ScGlobal::eLnge;
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
rDoc.GetCellType(rCol, nRow, 0, eType);
if (eType == CELLTYPE_VALUE)
{
- OUString aMonths[] = {"January", "February", "March", "April", "May",
- "June", "July", "August", "September", "October", "November", "December"};
-
double nVal = rDoc.GetValue(rCol, nRow, 0);
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
- Date aDate = getDate(nVal, pFormatter);
- rDoc.SetString(rCol, nRow, 0, aMonths[aDate.GetMonth() - 1]);
+ Color* pColor = nullptr;
+ OUString aResult;
+ pFormatter->GetPreviewStringGuess("MMMM", nVal, aResult, &pColor, eLanguage);
+ rDoc.SetString(rCol, nRow, 0, aResult);
}
}
}
break;
case DATETIME_TRANSFORMATION_TYPE::START_OF_MONTH:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
+ SvNumFormatType nFormatType = SvNumFormatType::DATE;
+ LanguageType eLanguage = ScGlobal::eLnge;
+ sal_uInt32 nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
@@ -910,16 +863,11 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
- SvNumFormatType nFormatType = SvNumFormatType::DATE;
- LanguageType eLanguage = ScGlobal::eLnge;
ScAddress aAddress(rCol, nRow, 0);
- sal_uLong nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
-
Date aDate = getDate(nVal, pFormatter);
- Date aStart(1,aDate.GetMonth(), aDate.GetYear());
- int nDays = aDate.GetDayOfYear() - aStart.GetDayOfYear() - 1;
- rDoc.SetValue(rCol, nRow, 0, nVal - nDays);
+ aDate.SetDay(1);
+ nVal = aDate - pFormatter->GetNullDate();
+ rDoc.SetValue(rCol, nRow, 0, nVal);
rDoc.SetNumberFormat(aAddress, nFormat);
}
}
@@ -927,6 +875,10 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::END_OF_MONTH:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
+ SvNumFormatType nFormatType = SvNumFormatType::DATE;
+ LanguageType eLanguage = ScGlobal::eLnge;
+ sal_uInt32 nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
@@ -934,17 +886,11 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
- SvNumFormatType nFormatType = SvNumFormatType::DATE;
- LanguageType eLanguage = ScGlobal::eLnge;
ScAddress aAddress(rCol, nRow, 0);
- sal_uLong nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
-
Date aDate = getDate(nVal, pFormatter);
- Date aEnd(aDate.GetDaysInMonth(),aDate.GetMonth(), aDate.GetYear());
-
- int nDays = aEnd.GetDayOfYear() - aDate.GetDayOfYear() + 1;
- rDoc.SetValue(rCol, nRow, 0, nVal + nDays);
+ aDate.SetDay(aDate.GetDaysInMonth());
+ nVal = aDate - pFormatter->GetNullDate();
+ rDoc.SetValue(rCol, nRow, 0, nVal);
rDoc.SetNumberFormat(aAddress, nFormat);
}
}
@@ -952,6 +898,7 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::DAY:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
@@ -959,7 +906,6 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
Date aDate = getDate(nVal, pFormatter);
rDoc.SetValue(rCol, nRow, 0, aDate.GetDay());
}
@@ -968,6 +914,7 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::DAY_OF_WEEK:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
@@ -975,7 +922,6 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
Date aDate = getDate(nVal, pFormatter);
rDoc.SetValue(rCol, nRow, 0, aDate.GetDayOfWeek());
}
@@ -984,6 +930,7 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::DAY_OF_YEAR:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
@@ -991,7 +938,6 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
Date aDate = getDate(nVal, pFormatter);
rDoc.SetValue(rCol, nRow, 0, aDate.GetDayOfYear());
}
@@ -1000,6 +946,7 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::QUARTER:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
@@ -1007,10 +954,9 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
Date aDate = getDate(nVal, pFormatter);
- int nMonth = 1 + aDate.GetMonth();
+ int nMonth = aDate.GetMonth();
if(nMonth >= 1 && nMonth <=3)
rDoc.SetValue(rCol, nRow, 0, 1);
@@ -1032,6 +978,10 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::START_OF_QUARTER:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
+ SvNumFormatType nFormatType = SvNumFormatType::DATE;
+ LanguageType eLanguage = ScGlobal::eLnge;
+ sal_uInt32 nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
CellType eType;
@@ -1039,44 +989,40 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
- SvNumFormatType nFormatType = SvNumFormatType::DATE;
- LanguageType eLanguage = ScGlobal::eLnge;
ScAddress aAddress(rCol, nRow, 0);
- sal_uLong nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
Date aDate = getDate(nVal, pFormatter);
int nMonth = aDate.GetMonth();
if(nMonth >= 1 && nMonth <=3)
{
- Date aQuarterDate(1,1,aDate.GetYear());
- int days = aDate.GetDayOfYear() - aQuarterDate.GetDayOfYear() - 1;
- nVal -= days;
+ aDate.SetDay(1);
+ aDate.SetMonth(1);
+ nVal = aDate - pFormatter->GetNullDate();
rDoc.SetValue(rCol, nRow, 0, nVal);
rDoc.SetNumberFormat(aAddress, nFormat);
}
else if(nMonth >= 4 && nMonth <=6)
{
- Date aQuarterDate(1,4,aDate.GetYear());
- int days = aDate.GetDayOfYear() - aQuarterDate.GetDayOfYear() - 1;
- nVal -= days;
+ aDate.SetDay(1);
+ aDate.SetMonth(4);
+ nVal = aDate - pFormatter->GetNullDate();
rDoc.SetValue(rCol, nRow, 0, nVal);
rDoc.SetNumberFormat(aAddress, nFormat);
}
else if(nMonth >= 7 && nMonth <=9)
{
- Date aQuarterDate(1,7,aDate.GetYear());
- int days = aDate.GetDayOfYear() - aQuarterDate.GetDayOfYear() - 1;
- nVal -= days;
+ aDate.SetDay(1);
+ aDate.SetMonth(7);
+ nVal = aDate - pFormatter->GetNullDate();
rDoc.SetValue(rCol, nRow, 0, nVal);
rDoc.SetNumberFormat(aAddress, nFormat);
}
else if(nMonth >= 10 && nMonth <=12)
{
- Date aQuarterDate(1,10,aDate.GetYear());
- int days = aDate.GetDayOfYear() - aQuarterDate.GetDayOfYear() - 1;
- nVal -= days;
+ aDate.SetDay(1);
+ aDate.SetMonth(10);
+ nVal = aDate - pFormatter->GetNullDate();
rDoc.SetValue(rCol, nRow, 0, nVal);
rDoc.SetNumberFormat(aAddress, nFormat);
}
@@ -1088,55 +1034,53 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::END_OF_QUARTER:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
+ SvNumFormatType nFormatType = SvNumFormatType::DATE;
+ LanguageType eLanguage = ScGlobal::eLnge;
+ sal_uInt32 nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
- SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
- SvNumFormatType nFormatType = SvNumFormatType::DATE;
- LanguageType eLanguage = ScGlobal::eLnge;
ScAddress aAddress(rCol, nRow, 0);
- sal_uLong nFormat = pFormatter->GetStandardFormat( nFormatType, eLanguage );
CellType eType;
rDoc.GetCellType(rCol, nRow, 0, eType);
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- nVal = std::trunc(nVal);
Date aDate = getDate(nVal, pFormatter);
-
int nMonth = aDate.GetMonth();
if(nMonth >= 1 && nMonth <=3)
{
- Date aQuarterDate(31,3,aDate.GetYear());
- int days = aQuarterDate.GetDayOfYear() - aDate.GetDayOfYear() + 1;
- nVal += days;
+ aDate.SetDay(31);
+ aDate.SetMonth(3);
+ nVal = aDate - pFormatter->GetNullDate();
rDoc.SetValue(rCol, nRow, 0, nVal);
rDoc.SetNumberFormat(aAddress, nFormat);
}
else if(nMonth >= 4 && nMonth <=6)
{
- Date aQuarterDate(30,6,aDate.GetYear());
- int days = aQuarterDate.GetDayOfYear() - aDate.GetDayOfYear() + 1;
- nVal += days;
+ aDate.SetDay(30);
+ aDate.SetMonth(6);
+ nVal = aDate - pFormatter->GetNullDate();
rDoc.SetValue(rCol, nRow, 0, nVal);
rDoc.SetNumberFormat(aAddress, nFormat);
}
else if(nMonth >= 7 && nMonth <=9)
{
- Date aQuarterDate(30,9,aDate.GetYear());
- int days = aQuarterDate.GetDayOfYear() - aDate.GetDayOfYear() + 1;
- nVal += days;
+ aDate.SetDay(30);
+ aDate.SetMonth(9);
+ nVal = aDate - pFormatter->GetNullDate();
rDoc.SetValue(rCol, nRow, 0, nVal);
rDoc.SetNumberFormat(aAddress, nFormat);
}
else if(nMonth >= 10 && nMonth <=12)
{
- Date aQuarterDate(31,12,aDate.GetYear());
- int days = aQuarterDate.GetDayOfYear() - aDate.GetDayOfYear() + 1;
- nVal += days;
+ aDate.SetDay(31);
+ aDate.SetMonth(12);
+ nVal = aDate - pFormatter->GetNullDate();
rDoc.SetValue(rCol, nRow, 0, nVal);
rDoc.SetNumberFormat(aAddress, nFormat);
}
@@ -1149,14 +1093,18 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
break;
case DATETIME_TRANSFORMATION_TYPE::TIME:
{
+ SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
+ SvNumFormatType nFormatType = SvNumFormatType::TIME;
+ LanguageType eLanguage = ScGlobal::eLnge;
+ sal_uInt32 nFormat = pFormatter->GetStandardFormat(nFormatType, eLanguage);
for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
+ ScAddress aAddress(rCol, nRow, 0);
CellType eType;
rDoc.GetCellType(rCol, nRow, 0, eType);
if (eType == CELLTYPE_VALUE)
{
- double nVal = rDoc.GetValue(rCol, nRow, 0);
- rDoc.SetString(rCol, nRow, 0, getTimeString(nVal));
+ rDoc.SetNumberFormat(aAddress, nFormat);
}
}
}
@@ -1170,7 +1118,10 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- rDoc.SetValue(rCol, nRow, 0, getHour(nVal));
+ sal_uInt16 nHour, nMinute, nSecond;
+ double fFractionOfSecond;
+ tools::Time::GetClock( nVal, nHour, nMinute, nSecond, fFractionOfSecond, 0);
+ rDoc.SetValue(rCol, nRow, 0, nHour);
}
}
}
@@ -1184,7 +1135,10 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- rDoc.SetValue(rCol, nRow, 0, getMinute(nVal));
+ sal_uInt16 nHour, nMinute, nSecond;
+ double fFractionOfSecond;
+ tools::Time::GetClock( nVal, nHour, nMinute, nSecond, fFractionOfSecond, 0);
+ rDoc.SetValue(rCol, nRow, 0, nMinute);
}
}
}
@@ -1198,7 +1152,10 @@ void DateTimeTransformation::Transform(ScDocument& rDoc) const
if (eType == CELLTYPE_VALUE)
{
double nVal = rDoc.GetValue(rCol, nRow, 0);
- rDoc.SetValue(rCol, nRow, 0, getSecond(nVal));
+ sal_uInt16 nHour, nMinute, nSecond;
+ double fFractionOfSecond;
+ tools::Time::GetClock( nVal, nHour, nMinute, nSecond, fFractionOfSecond, 0);
+ rDoc.SetValue(rCol, nRow, 0, nSecond);
}
}
}
More information about the Libreoffice-commits
mailing list