summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-07-20 18:32:57 +0200
committerEike Rathke <erack@redhat.com>2017-07-21 12:24:27 +0200
commitfcd0361d6be8d088be12e500f0120afd7995d1ac (patch)
tree9e18c0310405d68d9151db9073cc8f6926df077d /tools
parent2e486daff35ab16e810bfdafb24b19bcbf2fe8cd (diff)
Eliminate Date::operator+=() and -=() and replace with Date::AddDays()
Clarifies code and gets rid of explicitly casting the operand to sal_Int32. Also in preparation of removing DateTime::operator+=(sal_Int32) that is confusingly similar to DateTime::operator+=(double) and just depends on type. Change-Id: I83422e2940fbb017978db9b5734b4966228af3de Reviewed-on: https://gerrit.libreoffice.org/40248 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/qa/cppunit/test_date.cxx30
-rw-r--r--tools/source/datetime/datetime.cxx6
-rw-r--r--tools/source/datetime/tdate.cxx16
3 files changed, 26 insertions, 26 deletions
diff --git a/tools/qa/cppunit/test_date.cxx b/tools/qa/cppunit/test_date.cxx
index 4f36baa07564..74d37efe5201 100644
--- a/tools/qa/cppunit/test_date.cxx
+++ b/tools/qa/cppunit/test_date.cxx
@@ -39,9 +39,11 @@ void DateTest::testDate()
CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(1), aCE - aBCE);
CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(-1), aBCE - aCE);
aDate = aBCE;
- CPPUNIT_ASSERT_EQUAL( aCE.GetDate(), (aDate += 1).GetDate());
+ aDate.AddDays(1);
+ CPPUNIT_ASSERT_EQUAL( aCE.GetDate(), aDate.GetDate());
aDate = aCE;
- CPPUNIT_ASSERT_EQUAL( aBCE.GetDate(), (aDate -= 1).GetDate());
+ aDate.AddDays(-1);
+ CPPUNIT_ASSERT_EQUAL( aBCE.GetDate(), aDate.GetDate());
// The entire BCE and CE ranges cover that many days. Day 0 is -0001-12-31
CPPUNIT_ASSERT_EQUAL( kMaxDays, aMax - aBCE);
@@ -49,13 +51,17 @@ void DateTest::testDate()
// Truncate at limits, not under-/overflow or wrap.
aDate = aMin;
- CPPUNIT_ASSERT_EQUAL( aMin.GetDate(), (aDate -= 1).GetDate());
+ aDate.AddDays(-1);
+ CPPUNIT_ASSERT_EQUAL( aMin.GetDate(), aDate.GetDate());
aDate = aMax;
- CPPUNIT_ASSERT_EQUAL( aMax.GetDate(), (aDate += 1).GetDate());
+ aDate.AddDays(1);
+ CPPUNIT_ASSERT_EQUAL( aMax.GetDate(), aDate.GetDate());
aDate = aBCE;
- CPPUNIT_ASSERT_EQUAL( aMin.GetDate(), (aDate += (kMinDays-10)).GetDate());
+ aDate.AddDays(kMinDays-10);
+ CPPUNIT_ASSERT_EQUAL( aMin.GetDate(), aDate.GetDate());
aDate = aBCE;
- CPPUNIT_ASSERT_EQUAL( aMax.GetDate(), (aDate += (kMaxDays+10)).GetDate());
+ aDate.AddDays(kMaxDays+10);
+ CPPUNIT_ASSERT_EQUAL( aMax.GetDate(), aDate.GetDate());
aDate = aMax;
aDate.SetDay(32);
aDate.Normalize();
@@ -109,14 +115,18 @@ void DateTest::testDate()
// Year -1 is a leap year.
aDate = Date(28,2,-1);
- CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), (aDate += 1).GetDate());
+ aDate.AddDays(1);
+ CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), aDate.GetDate());
aDate = Date(1,3,-1);
- CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), (aDate -= 1).GetDate());
+ aDate.AddDays(-1);
+ CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), aDate.GetDate());
// Year -5 is a leap year.
aDate = Date(28,2,-5);
- CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), (aDate += 1).GetDate());
+ aDate.AddDays(1);
+ CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), aDate.GetDate());
aDate = Date(1,3,-5);
- CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), (aDate -= 1).GetDate());
+ aDate.AddDays(-1);
+ CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), aDate.GetDate());
}
CPPUNIT_TEST_SUITE_REGISTRATION(DateTest);
diff --git a/tools/source/datetime/datetime.cxx b/tools/source/datetime/datetime.cxx
index aa17d65796e6..b87fcdfe8efe 100644
--- a/tools/source/datetime/datetime.cxx
+++ b/tools/source/datetime/datetime.cxx
@@ -190,7 +190,7 @@ DateTime& DateTime::operator +=( double fTimeInDays )
fInt = ::rtl::math::approxFloor( fTimeInDays );
fFrac = fInt >= fTimeInDays ? 0.0 : fTimeInDays - fInt;
}
- Date::operator+=( sal_Int32(fInt) ); // full days
+ AddDays( sal_Int32(fInt) ); // full days
if ( fFrac )
{
tools::Time aTime(0); // default ctor calls system time, we don't need that
@@ -268,7 +268,7 @@ DateTime DateTime::CreateFromWin32FileDateTime( sal_uInt32 rLower, sal_uInt32 rU
Date aDate(1,1,1601);
// (0xffffffffffffffff / a100nPerDay = 21350398) fits into sal_Int32
// (0x7fffffff = 2147483647)
- aDate += static_cast<sal_Int32>(nDays);
+ aDate.AddDays(nDays);
SAL_WARN_IF( aDate - Date(1,1,1601) != static_cast<sal_Int32>(nDays), "tools.datetime",
"DateTime::CreateFromWin32FileDateTime - date truncated to max");
@@ -287,7 +287,7 @@ DateTime DateTime::CreateFromUnixTime(const double fSecondsSinceEpoch)
const sal_Int32 nDays = static_cast <sal_Int32>(::rtl::math::approxFloor(fValue));
Date aDate (1, 1, 1970);
- aDate += nDays;
+ aDate.AddDays(nDays);
SAL_WARN_IF(aDate - Date(1, 1, 1970) != static_cast<sal_Int32>(nDays), "tools.datetime",
"DateTime::CreateFromUnixTime - date truncated to max");
diff --git a/tools/source/datetime/tdate.cxx b/tools/source/datetime/tdate.cxx
index 4206b13c2dd1..1829806b1be1 100644
--- a/tools/source/datetime/tdate.cxx
+++ b/tools/source/datetime/tdate.cxx
@@ -571,20 +571,10 @@ bool Date::Normalize( sal_uInt16 & rDay, sal_uInt16 & rMonth, sal_Int16 & rYear
return true;
}
-Date& Date::operator +=( sal_Int32 nDays )
+void Date::AddDays( sal_Int32 nDays )
{
if (nDays != 0)
*this = lcl_DaysToDate( GetAsNormalizedDays() + nDays );
-
- return *this;
-}
-
-Date& Date::operator -=( sal_Int32 nDays )
-{
- if (nDays != 0)
- *this = lcl_DaysToDate( GetAsNormalizedDays() - nDays );
-
- return *this;
}
Date& Date::operator ++()
@@ -602,14 +592,14 @@ Date& Date::operator --()
Date operator +( const Date& rDate, sal_Int32 nDays )
{
Date aDate( rDate );
- aDate += nDays;
+ aDate.AddDays( nDays );
return aDate;
}
Date operator -( const Date& rDate, sal_Int32 nDays )
{
Date aDate( rDate );
- aDate -= nDays;
+ aDate.AddDays( -nDays );
return aDate;
}