summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2021-03-23 10:54:14 +0100
committerEike Rathke <erack@redhat.com>2021-04-04 19:54:49 +0200
commitd78d44bfbf4b1ae7aa68b38fdfc916de47fce05f (patch)
tree3ae5b9baeb155b9c72cc3dadd70f61b0a05d5db8 /sc
parent642501ecb94cef11592ecc49b7a13ba5bdbb8d62 (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 'sc')
-rw-r--r--sc/inc/global.hxx1
-rw-r--r--sc/qa/unit/ucalc.cxx16
-rw-r--r--sc/source/core/data/table4.cxx23
3 files changed, 36 insertions, 4 deletions
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index 3574a0aab0ed..21d33ccc35e9 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -346,6 +346,7 @@ enum FillDateCmd
FILL_DAY,
FILL_WEEKDAY,
FILL_MONTH,
+ FILL_END_OF_MONTH,
FILL_YEAR
};
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index f5da5620744c..5b339eba8f67 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -4831,6 +4831,22 @@ void Test::testAutoFill()
CPPUNIT_ASSERT_EQUAL(aExpected, aFormula);
}
+ // Clear column A for a new test.
+ clearRange(m_pDoc, ScRange(0, 0, 0, 0, MAXROW, 0));
+ m_pDoc->SetRowHidden(0, MAXROW, 0, false); // Show all rows.
+
+ m_pDoc->SetString(0, 100, 0, "2019-10-31");
+ m_pDoc->SetString(0, 101, 0, "2019-11-30");
+ m_pDoc->SetString(0, 102, 0, "2019-12-31");
+ m_pDoc->Fill(0, 100, 0, 102, nullptr, aMarkData, 3, FILL_TO_BOTTOM, FILL_AUTO);
+
+ // tdf#58745, Without the fix in place, this test would have failed with
+ // - Expected: 2020-01-31
+ // - Actual : 2019-01-11
+ CPPUNIT_ASSERT_EQUAL(OUString("2020-01-31"), m_pDoc->GetString(0, 103, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("2020-02-29"), m_pDoc->GetString(0, 104, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("2020-03-31"), m_pDoc->GetString(0, 105, 0));
+
m_pDoc->DeleteTab(0);
}
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index ede354eead8c..392eb8847028 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -534,7 +534,12 @@ void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
tools::Long nDDiff = aDate2.GetDay() - static_cast<tools::Long>(aDate1.GetDay());
tools::Long nMDiff = aDate2.GetMonth() - static_cast<tools::Long>(aDate1.GetMonth());
tools::Long nYDiff = aDate2.GetYear() - static_cast<tools::Long>(aDate1.GetYear());
- if ( nDDiff )
+ if (nMDiff && aDate1.IsEndOfMonth() && aDate2.IsEndOfMonth())
+ {
+ eType = FILL_END_OF_MONTH;
+ nCmpInc = nMDiff + 12 * nYDiff;
+ }
+ else if (nDDiff)
{
eType = FILL_DAY;
nCmpInc = aDate2 - aDate1;
@@ -565,7 +570,8 @@ void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
nDDiff = aDate2.GetDay() - static_cast<tools::Long>(aDate1.GetDay());
nMDiff = aDate2.GetMonth() - static_cast<tools::Long>(aDate1.GetMonth());
nYDiff = aDate2.GetYear() - static_cast<tools::Long>(aDate1.GetYear());
- if (nDDiff || ( nMDiff + 12 * nYDiff != nCmpInc ))
+ if ((nDDiff && !aDate1.IsEndOfMonth() && !aDate2.IsEndOfMonth())
+ || (nMDiff + 12 * nYDiff != nCmpInc))
bVal = false;
}
aDate1 = aDate2;
@@ -577,7 +583,8 @@ void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
}
if (bVal)
{
- if ( eType == FILL_MONTH && ( nCmpInc % 12 == 0 ) )
+ if ((eType == FILL_MONTH || eType == FILL_END_OF_MONTH)
+ && (nCmpInc % 12 == 0))
{
eType = FILL_YEAR;
nCmpInc /= 12;
@@ -1513,6 +1520,7 @@ void ScTable::IncDate(double& rVal, sal_uInt16& nDayOfMonth, double nStep, FillD
}
break;
case FILL_MONTH:
+ case FILL_END_OF_MONTH:
{
if ( nDayOfMonth == 0 )
nDayOfMonth = aDate.GetDay(); // init
@@ -1548,7 +1556,14 @@ void ScTable::IncDate(double& rVal, sal_uInt16& nDayOfMonth, double nStep, FillD
{
aDate.SetMonth(static_cast<sal_uInt16>(nMonth));
aDate.SetYear(static_cast<sal_uInt16>(nYear));
- aDate.SetDay( std::min( Date::GetDaysInMonth( nMonth, nYear), nDayOfMonth ) );
+ if (eCmd == FILL_END_OF_MONTH)
+ {
+ aDate.SetDay(Date::GetDaysInMonth(nMonth, nYear));
+ }
+ else
+ {
+ aDate.SetDay(std::min(Date::GetDaysInMonth(nMonth, nYear), nDayOfMonth));
+ }
}
}
break;