summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2021-03-23 10:54:14 +0100
committerAndras Timar <andras.timar@collabora.com>2021-04-06 10:18:10 +0200
commit2ffe3b511b9563549435843253f4dfd042a7bb2b (patch)
tree18ec2ec5d0dfb49db6d8efb85b6982e32110fffe /tools
parentb56dc807439d7174e223f9775c614488951b4d14 (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> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113156 Reviewed-by: Eike Rathke <erack@redhat.com>
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();