include/tools/date.hxx | 8 ++++---- tools/qa/cppunit/test_date.cxx | 17 +++++++++++++++++ tools/source/datetime/tdate.cxx | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-)
New commits: commit 0e65e82238c8ded807d022234029163dc5b67f0a Author: Eike Rathke <[email protected]> Date: Fri Apr 28 17:21:30 2017 +0200 Adapt documentation to reality Change-Id: Ic76cdff3c95e68e91700ca7143e8aa8c908ed56e diff --git a/include/tools/date.hxx b/include/tools/date.hxx index bab1efd833f8..600c4f90a562 100644 --- a/include/tools/date.hxx +++ b/include/tools/date.hxx @@ -164,8 +164,8 @@ public: /** If the represented date is valid (1<=month<=12, 1<=day<=(28,29,30,31) depending on month/year) AND is of the Gregorian calendar (1582-10-15 - <= date) (AND implicitly date <= 9999-12-31 due to internal - representation) */ + <= date) + */ bool IsValidAndGregorian() const; /** If the represented date is valid (1<=month<=12, 1<=day<=(28,29,30,31) @@ -175,8 +175,8 @@ public: /** Normalize date, invalid day or month values are adapted such that they carry over to the next month or/and year, for example 1999-02-32 becomes 1999-03-04, 1999-13-01 becomes 2000-01-01, 1999-13-42 becomes - 2000-02-11. Truncates at 9999-12-31, 0000-00-x will yield the - normalized value of 0000-01-max(1,(x-31)) + 2000-02-11. Truncates at -32768-01-01 or 32767-12-31, 0001-00-x will + yield the normalized value of -0001-12-x This may be necessary after Date ctors or if the SetDate(), SetDay(), SetMonth(), SetYear() methods set individual non-matching values. commit 8bdbfdb97d94745454b2ad87d341bcb32d10461c Author: Eike Rathke <[email protected]> Date: Fri Apr 28 17:14:32 2017 +0200 Add unit tests for Date::Normalize() Change-Id: I4edb04748b1f407eb6ce17cd24ff022cef6e1f67 diff --git a/tools/qa/cppunit/test_date.cxx b/tools/qa/cppunit/test_date.cxx index 0ee30089b7b5..c2c31e10b51c 100644 --- a/tools/qa/cppunit/test_date.cxx +++ b/tools/qa/cppunit/test_date.cxx @@ -56,6 +56,23 @@ void DateTest::testDate() CPPUNIT_ASSERT_EQUAL( aMin.GetDate(), (aDate += (kMinDays-10)).GetDate()); aDate = aBCE; CPPUNIT_ASSERT_EQUAL( aMax.GetDate(), (aDate += (kMaxDays+10)).GetDate()); + aDate = aMax; + aDate.SetDay(32); + aDate.Normalize(); + CPPUNIT_ASSERT_EQUAL( aMax.GetDate(), aDate.GetDate()); + + // 0001-00-x normalized to -0001-12-x + aDate.SetYear(1); + aDate.SetMonth(0); + aDate.SetDay(22); + aDate.Normalize(); + CPPUNIT_ASSERT_EQUAL( Date(22,12,-1).GetDate(), aDate.GetDate()); + // 1999-02-32 normalized to 1999-03-04 + aDate.SetYear(1999); + aDate.SetMonth(2); + aDate.SetDay(32); + aDate.Normalize(); + CPPUNIT_ASSERT_EQUAL( Date(4,3,1999).GetDate(), aDate.GetDate()); // Year -1 is a leap year. aDate = Date(28,2,-1); commit 9054648bab5d4d89e7e3654847102d62ab9e77a1 Author: Eike Rathke <[email protected]> Date: Fri Apr 28 17:03:52 2017 +0200 Month 100 was always wrong Though only in case localtime() couldn't be obtained, which is about ~never. Fallout from commit a3de32acc06cfcf9bb343a29c4b9854c92645f70 Date: Wed Oct 28 11:23:36 2015 +0100 Rename (private) Date::init and reuse it Change-Id: Idbbac69f3d90e7556cd83bbf442ef8ccaecec86e diff --git a/tools/source/datetime/tdate.cxx b/tools/source/datetime/tdate.cxx index 05a1e5a1d370..46e5ad62469e 100644 --- a/tools/source/datetime/tdate.cxx +++ b/tools/source/datetime/tdate.cxx @@ -228,7 +228,7 @@ Date::Date( DateInitSystem ) static_cast<sal_uInt16>(aTime.tm_year+1900) ); } else - setDateFromDMY( 1, 100, 1900 ); + setDateFromDMY( 1, 1, 1900 ); #endif } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
