diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qa/cppunit/test_date.cxx | 25 | ||||
-rw-r--r-- | tools/source/datetime/tdate.cxx | 11 |
2 files changed, 36 insertions, 0 deletions
diff --git a/tools/qa/cppunit/test_date.cxx b/tools/qa/cppunit/test_date.cxx index 9a243cce504c..e11270e6a299 100644 --- a/tools/qa/cppunit/test_date.cxx +++ b/tools/qa/cppunit/test_date.cxx @@ -26,6 +26,7 @@ public: void testGetDayOfWeek(); void testGetDaysInMonth(); void testIsBetween(); + void testIsEndOfMonth(); CPPUNIT_TEST_SUITE(DateTest); CPPUNIT_TEST(testDate); @@ -37,6 +38,7 @@ public: CPPUNIT_TEST(testGetDayOfWeek); CPPUNIT_TEST(testGetDaysInMonth); CPPUNIT_TEST(testIsBetween); + CPPUNIT_TEST(testIsEndOfMonth); CPPUNIT_TEST_SUITE_END(); }; @@ -533,6 +535,29 @@ void DateTest::testIsBetween() CPPUNIT_ASSERT(aDate.IsBetween(Date(1, 1, 2018), Date(1, 12, 2018))); } +void DateTest::testIsEndOfMonth() +{ + { + Date aDate(31, 12, 2000); + CPPUNIT_ASSERT(aDate.IsEndOfMonth()); + } + + { + Date aDate(30, 12, 2000); + CPPUNIT_ASSERT(!aDate.IsEndOfMonth()); + } + + { + Date aDate(29, 2, 2000); + CPPUNIT_ASSERT(aDate.IsEndOfMonth()); + } + + { + Date aDate(28, 2, 2000); + CPPUNIT_ASSERT(!aDate.IsEndOfMonth()); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(DateTest); } diff --git a/tools/source/datetime/tdate.cxx b/tools/source/datetime/tdate.cxx index a38fb8e986c3..979611333813 100644 --- a/tools/source/datetime/tdate.cxx +++ b/tools/source/datetime/tdate.cxx @@ -452,6 +452,17 @@ bool Date::IsValidDate( sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear ) return true; } +bool Date::IsEndOfMonth() const +{ + return IsEndOfMonth(GetDay(), GetMonth(), GetYear()); +} + +//static +bool Date::IsEndOfMonth(sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear) +{ + return IsValidDate(nDay, nMonth, nYear) && ImplDaysInMonth(nMonth, nYear) == nDay; +} + void Date::Normalize() { sal_uInt16 nDay = GetDay(); |