From fcd0361d6be8d088be12e500f0120afd7995d1ac Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Thu, 20 Jul 2017 18:32:57 +0200 Subject: Eliminate Date::operator+=() and -=() and replace with Date::AddDays() Clarifies code and gets rid of explicitly casting the operand to sal_Int32. Also in preparation of removing DateTime::operator+=(sal_Int32) that is confusingly similar to DateTime::operator+=(double) and just depends on type. Change-Id: I83422e2940fbb017978db9b5734b4966228af3de Reviewed-on: https://gerrit.libreoffice.org/40248 Reviewed-by: Eike Rathke Tested-by: Eike Rathke --- sc/source/core/data/conditio.cxx | 2 +- sc/source/core/data/dpgroup.cxx | 2 +- sc/source/core/data/dptabdat.cxx | 2 +- sc/source/core/data/dputil.cxx | 4 ++-- sc/source/core/data/table4.cxx | 16 ++++++++-------- sc/source/core/tool/interpr2.cxx | 28 ++++++++++++++-------------- sc/source/ui/cctrl/checklistmenu.cxx | 2 +- sc/source/ui/dbgui/dpgroupdlg.cxx | 2 +- sc/source/ui/docshell/docsh8.cxx | 2 +- sc/source/ui/view/cellsh1.cxx | 4 ++-- 10 files changed, 32 insertions(+), 32 deletions(-) (limited to 'sc') diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index 3f83ea2de188..a3a7853b9c6f 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -1624,7 +1624,7 @@ bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const double nVal = rCell.getValue(); sal_Int32 nCellDate = static_cast(::rtl::math::approxFloor(nVal)); Date aCellDate = pFormatter->GetNullDate(); - aCellDate += static_cast(::rtl::math::approxFloor(nVal)); + aCellDate.AddDays(nCellDate); switch(meType) { diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx index 705d62dff6b5..3e36951f3258 100644 --- a/sc/source/core/data/dpgroup.cxx +++ b/sc/source/core/data/dpgroup.cxx @@ -286,7 +286,7 @@ bool isDateInGroup(const ScDPItemData& rGroupItem, const ScDPItemData& rChildIte nGroupPart == css::sheet::DataPilotFieldGroupBy::QUARTERS) { Date aDate(1, 1, SC_DP_LEAPYEAR); - aDate += (nChildValue - 1); // days are 1-based + aDate.AddDays(nChildValue - 1); // days are 1-based sal_Int32 nCompare = aDate.GetMonth(); if (nGroupPart == css::sheet::DataPilotFieldGroupBy::QUARTERS) nCompare = ( ( nCompare - 1 ) / 3 ) + 1; // get quarter from date diff --git a/sc/source/core/data/dptabdat.cxx b/sc/source/core/data/dptabdat.cxx index 5e44937bc04f..1481849cc19c 100644 --- a/sc/source/core/data/dptabdat.cxx +++ b/sc/source/core/data/dptabdat.cxx @@ -66,7 +66,7 @@ long ScDPTableData::GetDatePart( long nDateVal, long nHierarchy, long nLevel ) return nLastRet; Date aDate( 30,12,1899 ); //TODO: get from source data (and cache here) - aDate += nDateVal; + aDate.AddDays( nDateVal); long nRet = 0; switch (nHierarchy) diff --git a/sc/source/core/data/dputil.cxx b/sc/source/core/data/dputil.cxx index 00b8b26d335c..a543a326bb4d 100644 --- a/sc/source/core/data/dputil.cxx +++ b/sc/source/core/data/dputil.cxx @@ -121,7 +121,7 @@ OUString ScDPUtil::getDateGroupName( case sheet::DataPilotFieldGroupBy::DAYS: { Date aDate(1, 1, SC_DP_LEAPYEAR); - aDate += (nValue - 1); // nValue is 1-based + aDate.AddDays(nValue - 1); // nValue is 1-based long nDays = aDate - pFormatter->GetNullDate(); const sal_uInt32 nFormat = pFormatter->GetFormatIndex(NF_DATE_SYS_DDMMM, ScGlobal::eLnge); @@ -334,7 +334,7 @@ sal_Int32 ScDPUtil::getDatePartValue( else { Date aDate = pFormatter->GetNullDate(); - aDate += static_cast(::rtl::math::approxFloor(fValue)); + aDate.AddDays(::rtl::math::approxFloor(fValue)); switch ( nDatePart ) { diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx index f211d97a5619..fb122318a1ff 100644 --- a/sc/source/core/data/table4.cxx +++ b/sc/source/core/data/table4.cxx @@ -270,10 +270,10 @@ void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, Date aNullDate = pDocument->GetFormatTable()->GetNullDate(); Date aDate1 = aNullDate; nVal = aFirstCell.mfValue; - aDate1 += static_cast(nVal); + aDate1.AddDays(nVal); Date aDate2 = aNullDate; nVal = GetValue(nCol+nAddX, nRow+nAddY); - aDate2 += static_cast(nVal); + aDate2.AddDays(nVal); if ( aDate1 != aDate2 ) { long nCmpInc = 0; @@ -1079,26 +1079,26 @@ void ScTable::IncDate(double& rVal, sal_uInt16& nDayOfMonth, double nStep, FillD long nInc = (long) nStep; // upper/lower limits ? Date aNullDate = pDocument->GetFormatTable()->GetNullDate(); Date aDate = aNullDate; - aDate += static_cast(rVal); + aDate.AddDays(rVal); switch (eCmd) { case FILL_WEEKDAY: { - aDate += nInc; + aDate.AddDays(nInc); DayOfWeek eWeekDay = aDate.GetDayOfWeek(); if (nInc >= 0) { if (eWeekDay == SATURDAY) - aDate += 2; + aDate.AddDays(2); else if (eWeekDay == SUNDAY) - aDate += 1; + aDate.AddDays(1); } else { if (eWeekDay == SATURDAY) - aDate -= 1; + aDate.AddDays(-1); else if (eWeekDay == SUNDAY) - aDate -= 2; + aDate.AddDays(-2); } } break; diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index 3c3a5f41bd83..08a36f577309 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -92,7 +92,7 @@ double ScInterpreter::GetDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int1 } Date aDate( nD, nM, nY); if (!bStrict) - aDate += nDay - 1; + aDate.AddDays( nDay - 1 ); if (aDate.IsValidAndGregorian()) return (double) (aDate - pFormatter->GetNullDate()); else @@ -126,21 +126,21 @@ void ScInterpreter::ScGetActTime() void ScInterpreter::ScGetYear() { Date aDate = pFormatter->GetNullDate(); - aDate += GetInt32(); + aDate.AddDays( GetInt32()); PushDouble( (double) aDate.GetYear() ); } void ScInterpreter::ScGetMonth() { Date aDate = pFormatter->GetNullDate(); - aDate += GetInt32(); + aDate.AddDays( GetInt32()); PushDouble( (double) aDate.GetMonth() ); } void ScInterpreter::ScGetDay() { Date aDate = pFormatter->GetNullDate(); - aDate += GetInt32(); + aDate.AddDays( GetInt32()); PushDouble((double) aDate.GetDay()); } @@ -200,7 +200,7 @@ void ScInterpreter::ScGetDayOfWeek() nFlag = 1; Date aDate = pFormatter->GetNullDate(); - aDate += GetInt32(); + aDate.AddDays( GetInt32()); int nVal = (int) aDate.GetDayOfWeek(); // MONDAY = 0 switch (nFlag) { @@ -242,7 +242,7 @@ void ScInterpreter::ScWeeknumOOo() sal_Int16 nFlag = GetInt16(); Date aDate = pFormatter->GetNullDate(); - aDate += GetInt32(); + aDate.AddDays( GetInt32()); PushInt( (int) aDate.GetWeekOfYear( nFlag == 1 ? SUNDAY : MONDAY )); } } @@ -259,7 +259,7 @@ void ScInterpreter::ScGetWeekOfYear() nFlag = GetInt16(); Date aDate = pFormatter->GetNullDate(); - aDate += GetInt32(); + aDate.AddDays( GetInt32()); sal_Int32 nMinimumNumberOfDaysInWeek; DayOfWeek eFirstDayOfWeek; @@ -302,7 +302,7 @@ void ScInterpreter::ScGetIsoWeekOfYear() if ( MustHaveParamCount( GetByte(), 1 ) ) { Date aDate = pFormatter->GetNullDate(); - aDate += GetInt32(); + aDate.AddDays( GetInt32()); PushInt( (int) aDate.GetWeekOfYear() ); } } @@ -737,11 +737,11 @@ void ScInterpreter::ScGetDiffDate360() else nSign = 1; Date aDate1 = pFormatter->GetNullDate(); - aDate1 += nDate1; + aDate1.AddDays( nDate1); Date aDate2 = pFormatter->GetNullDate(); - aDate2 += nDate2; + aDate2.AddDays( nDate2); if (aDate1.GetDay() == 31) - aDate1 -= (sal_uLong) 1; + aDate1.AddDays( -1); else if (!bFlag) { if (aDate1.GetMonth() == 2) @@ -763,7 +763,7 @@ void ScInterpreter::ScGetDiffDate360() if (!bFlag ) { if (aDate1.GetDay() == 30) - aDate2 -= (sal_uLong) 1; + aDate2.AddDays( -1); } else aDate2.SetDay(30); @@ -811,12 +811,12 @@ void ScInterpreter::ScGetDateDif() sal_uInt16 d1, m1, d2, m2; sal_Int16 y1, y2; Date aDate1( pFormatter->GetNullDate()); - aDate1 += nDate1; + aDate1.AddDays( nDate1); y1 = aDate1.GetYear(); m1 = aDate1.GetMonth(); d1 = aDate1.GetDay(); Date aDate2( pFormatter->GetNullDate()); - aDate2 += nDate2; + aDate2.AddDays( nDate2); y2 = aDate2.GetYear(); m2 = aDate2.GetMonth(); d2 = aDate2.GetDay(); diff --git a/sc/source/ui/cctrl/checklistmenu.cxx b/sc/source/ui/cctrl/checklistmenu.cxx index 9a04bad76bc1..b5729dc4b47d 100644 --- a/sc/source/ui/cctrl/checklistmenu.cxx +++ b/sc/source/ui/cctrl/checklistmenu.cxx @@ -1435,7 +1435,7 @@ void ScCheckListMenuWindow::addDateMember(const OUString& rsName, double nVal, b // Convert the numeric date value to a date object. Date aDate = pFormatter->GetNullDate(); - aDate += static_cast(rtl::math::approxFloor(nVal)); + aDate.AddDays(rtl::math::approxFloor(nVal)); sal_Int16 nYear = aDate.GetYear(); sal_uInt16 nMonth = aDate.GetMonth(); diff --git a/sc/source/ui/dbgui/dpgroupdlg.cxx b/sc/source/ui/dbgui/dpgroupdlg.cxx index e29cf9360f83..a8071c7b5ea6 100644 --- a/sc/source/ui/dbgui/dpgroupdlg.cxx +++ b/sc/source/ui/dbgui/dpgroupdlg.cxx @@ -141,7 +141,7 @@ bool ScDPDateGroupEditHelper::ImplGetValue( double& rfValue ) const void ScDPDateGroupEditHelper::ImplSetValue( double fValue ) { Date aDate( maNullDate ); - aDate += static_cast< sal_Int32 >( fValue ); + aDate.AddDays( fValue ); mpEdValue->SetDate( aDate ); } diff --git a/sc/source/ui/docshell/docsh8.cxx b/sc/source/ui/docshell/docsh8.cxx index 47b58ab1c08f..bdb2032c36ac 100644 --- a/sc/source/ui/docshell/docsh8.cxx +++ b/sc/source/ui/docshell/docsh8.cxx @@ -967,7 +967,7 @@ ErrCode ScDocShell::DBaseExport( const OUString& rFullFileName, rtl_TextEncoding else { Date aDate = pNumFmt->GetNullDate(); // tools date - aDate += static_cast(fVal); //! approxfloor? + aDate.AddDays(fVal); //! approxfloor? xRowUpdate->updateDate( nCol+1, aDate.GetUNODate() ); } } diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index c576d27c8cad..e559a6b782c8 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -691,9 +691,9 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) { const Date& rNullDate = pDoc->GetFormatTable()->GetNullDate(); Date aStartDate = rNullDate; - aStartDate += static_cast(fStartVal); + aStartDate.AddDays(fStartVal); Date aEndDate = rNullDate; - aEndDate += static_cast(fInputEndVal); + aEndDate.AddDays(fInputEndVal); double fTempDate=0; if(aStartDate.GetYear()!=aEndDate.GetYear()) -- cgit