summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2021-03-23 10:54:14 +0100
committerAndreas Heinisch <andreas.heinisch@yahoo.de>2021-03-25 09:42:40 +0100
commitea61644abe9e7cd35cdb54452dac327782bbc402 (patch)
tree0bec03e2b405c54060d3c4425bad7e6428f83559 /tools
parent89af24074e9adac4d005dcc322d81db09fc19f54 (diff)
tdf#58745 - Detect end of month when extending a date list
Change-Id: Icaa64a493598dc4bb8f2d6d076ad4300e2e4dde6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112976 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
Diffstat (limited to 'tools')
-rw-r--r--tools/qa/cppunit/test_date.cxx25
-rw-r--r--tools/source/datetime/tdate.cxx11
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();