diff options
27 files changed, 118 insertions, 116 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 56fa68c2aa52..f1b5b7d3365e 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -1702,7 +1702,7 @@ sal_Int16 implGetDateDay( double aDate ) aDate -= 2.0; // standardize: 1.1.1900 => 0.0 aDate = floor( aDate ); Date aRefDate( 1, 1, 1900 ); - aRefDate += static_cast<sal_Int32>(aDate); + aRefDate.AddDays( aDate ); sal_Int16 nRet = (sal_Int16)( aRefDate.GetDay() ); return nRet; @@ -1711,9 +1711,9 @@ sal_Int16 implGetDateDay( double aDate ) sal_Int16 implGetDateMonth( double aDate ) { Date aRefDate( 1,1,1900 ); - long nDays = (long)aDate; + sal_Int32 nDays = (sal_Int32)aDate; nDays -= 2; // standardize: 1.1.1900 => 0.0 - aRefDate += nDays; + aRefDate.AddDays( nDays ); sal_Int16 nRet = (sal_Int16)( aRefDate.GetMonth() ); return nRet; } @@ -4582,7 +4582,7 @@ sal_Int16 implGetDateYear( double aDate ) Date aRefDate( 1,1,1900 ); long nDays = (long) aDate; nDays -= 2; // standardize: 1.1.1900 => 0.0 - aRefDate += nDays; + aRefDate.AddDays( nDays ); sal_Int16 nRet = aRefDate.GetYear(); return nRet; } @@ -4672,7 +4672,7 @@ bool implDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, if (nAddMonths) aCurDate.AddMonths( nAddMonths); if (nAddDays) - aCurDate += nAddDays; + aCurDate.AddDays( nAddDays); } long nDiffDays = GetDayDiff( aCurDate ); diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx index 1dbfa9db3285..a67de7407a6b 100644 --- a/basic/source/runtime/methods1.cxx +++ b/basic/source/runtime/methods1.cxx @@ -3037,9 +3037,9 @@ void SbRtl_Me(StarBASIC *, SbxArray & rPar, bool) sal_Int16 implGetWeekDay( double aDate, bool bFirstDayParam, sal_Int16 nFirstDay ) { Date aRefDate( 1,1,1900 ); - long nDays = (long) aDate; + sal_Int32 nDays = (sal_Int32) aDate; nDays -= 2; // normalize: 1.1.1900 => 0 - aRefDate += nDays; + aRefDate.AddDays( nDays); DayOfWeek aDay = aRefDate.GetDayOfWeek(); sal_Int16 nDay; if ( aDay != SUNDAY ) diff --git a/chart2/source/view/axes/DateHelper.cxx b/chart2/source/view/axes/DateHelper.cxx index afefa628ff89..f90ac57e7c5d 100644 --- a/chart2/source/view/axes/DateHelper.cxx +++ b/chart2/source/view/axes/DateHelper.cxx @@ -69,7 +69,7 @@ bool DateHelper::IsLessThanOneYearAway( const Date& rD1, const Date& rD2 ) double DateHelper::RasterizeDateValue( double fValue, const Date& rNullDate, long TimeResolution ) { - Date aDate(rNullDate); aDate += static_cast<sal_Int32>(::rtl::math::approxFloor(fValue)); + Date aDate(rNullDate); aDate.AddDays(::rtl::math::approxFloor(fValue)); switch(TimeResolution) { case css::chart::TimeUnit::DAY: diff --git a/chart2/source/view/axes/DateScaling.cxx b/chart2/source/view/axes/DateScaling.cxx index 449c25c461c9..663e55e1e386 100644 --- a/chart2/source/view/axes/DateScaling.cxx +++ b/chart2/source/view/axes/DateScaling.cxx @@ -59,7 +59,7 @@ double SAL_CALL DateScaling::doScaling( double value ) else { Date aDate(m_aNullDate); - aDate += static_cast<sal_Int32>(::rtl::math::approxFloor(value)); + aDate.AddDays(::rtl::math::approxFloor(value)); switch( m_nTimeUnit ) { case DAY: diff --git a/chart2/source/view/axes/ScaleAutomatism.cxx b/chart2/source/view/axes/ScaleAutomatism.cxx index 97d84fa310e5..f712ecf33f91 100644 --- a/chart2/source/view/axes/ScaleAutomatism.cxx +++ b/chart2/source/view/axes/ScaleAutomatism.cxx @@ -548,8 +548,8 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForDateTimeAxis( ExplicitIncrementData& rExplicitIncrement, bool bAutoMinimum, bool bAutoMaximum ) const { - Date aMinDate(m_aNullDate); aMinDate += static_cast<sal_Int32>(::rtl::math::approxFloor(rExplicitScale.Minimum)); - Date aMaxDate(m_aNullDate); aMaxDate += static_cast<sal_Int32>(::rtl::math::approxFloor(rExplicitScale.Maximum)); + Date aMinDate(m_aNullDate); aMinDate.AddDays(::rtl::math::approxFloor(rExplicitScale.Minimum)); + Date aMaxDate(m_aNullDate); aMaxDate.AddDays(::rtl::math::approxFloor(rExplicitScale.Maximum)); rExplicitIncrement.PostEquidistant = false; if( aMinDate > aMaxDate ) diff --git a/chart2/source/view/axes/Tickmarks_Dates.cxx b/chart2/source/view/axes/Tickmarks_Dates.cxx index b7ba8487b72a..2b14d86a4bc2 100644 --- a/chart2/source/view/axes/Tickmarks_Dates.cxx +++ b/chart2/source/view/axes/Tickmarks_Dates.cxx @@ -98,7 +98,7 @@ void DateTickFactory::getAllTicks( TickInfoArraysType& rAllTickInfos, bool bShif switch( m_aIncrement.MajorTimeInterval.TimeUnit ) { case DAY: - aDate += m_aIncrement.MajorTimeInterval.Number; + aDate.AddDays( m_aIncrement.MajorTimeInterval.Number ); break; case YEAR: aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MajorTimeInterval.Number ); @@ -129,7 +129,7 @@ void DateTickFactory::getAllTicks( TickInfoArraysType& rAllTickInfos, bool bShif switch( m_aIncrement.MinorTimeInterval.TimeUnit ) { case DAY: - aDate += m_aIncrement.MinorTimeInterval.Number; + aDate.AddDays( m_aIncrement.MinorTimeInterval.Number ); break; case YEAR: aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MinorTimeInterval.Number ); diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index 3697f9456601..b4173b69fe41 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -1382,11 +1382,11 @@ long VSeriesPlotter::calculateTimeResolutionOnXAxis() aNullDate = m_apNumberFormatterWrapper->getNullDate(); if( aIt!=aEnd ) { - Date aPrevious(aNullDate); aPrevious+=static_cast<sal_Int32>(rtl::math::approxFloor(*aIt)); + Date aPrevious(aNullDate); aPrevious.AddDays(rtl::math::approxFloor(*aIt)); ++aIt; for(;aIt!=aEnd;++aIt) { - Date aCurrent(aNullDate); aCurrent+=static_cast<sal_Int32>(rtl::math::approxFloor(*aIt)); + Date aCurrent(aNullDate); aCurrent.AddDays(rtl::math::approxFloor(*aIt)); if( nRet == css::chart::TimeUnit::YEAR ) { if( DateHelper::IsInSameYear( aPrevious, aCurrent ) ) diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 181b283545fe..20a4c1cb493c 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -1861,7 +1861,7 @@ bool ChartView::getExplicitValuesForAxis( //remove 'one' from max if( rExplicitScale.AxisType == css::chart2::AxisType::DATE ) { - Date aMaxDate(rExplicitScale.NullDate); aMaxDate += static_cast<sal_Int32>(::rtl::math::approxFloor(rExplicitScale.Maximum)); + Date aMaxDate(rExplicitScale.NullDate); aMaxDate.AddDays(::rtl::math::approxFloor(rExplicitScale.Maximum)); //for explicit scales with shifted categories we need one interval more switch( rExplicitScale.TimeResolution ) { diff --git a/connectivity/source/drivers/calc/CTable.cxx b/connectivity/source/drivers/calc/CTable.cxx index 52737b61aca6..eab69b4e9792 100644 --- a/connectivity/source/drivers/calc/CTable.cxx +++ b/connectivity/source/drivers/calc/CTable.cxx @@ -348,7 +348,7 @@ static void lcl_SetValue( ORowSetValue& rValue, const Reference<XSpreadsheet>& x if ( eCellType == CellContentType_VALUE ) { ::Date aDate( rNullDate ); - aDate += static_cast<sal_Int32>(::rtl::math::approxFloor( xCell->getValue() )); + aDate.AddDays(::rtl::math::approxFloor( xCell->getValue() )); rValue = aDate.GetUNODate(); } else @@ -402,7 +402,7 @@ static void lcl_SetValue( ORowSetValue& rValue, const Reference<XSpreadsheet>& x aDateTime.Hours = (sal_uInt16) nIntTime; ::Date aDate( rNullDate ); - aDate += nIntDays; + aDate.AddDays( nIntDays ); aDateTime.Day = aDate.GetDay(); aDateTime.Month = aDate.GetMonth(); aDateTime.Year = aDate.GetYear(); diff --git a/include/tools/date.hxx b/include/tools/date.hxx index 3e038beb308b..071b3c3b765c 100644 --- a/include/tools/date.hxx +++ b/include/tools/date.hxx @@ -125,6 +125,10 @@ public: */ void AddMonths( sal_Int32 nAddMonths ); + /** Add days skipping year 0 and truncating at limits. + */ + void AddDays( sal_Int32 nAddDays ); + /** Obtain the day of the week for the date. Internally normalizes a copy of values. @@ -216,8 +220,6 @@ public: { mnDate = rDate.mnDate; return *this; } Date& operator =( const css::util::Date& rUDate ) { setDateFromDMY( rUDate.Day, rUDate.Month, rUDate.Year); return *this; } - Date& operator +=( sal_Int32 nDays ); - Date& operator -=( sal_Int32 nDays ); Date& operator ++(); Date& operator --(); diff --git a/include/tools/datetime.hxx b/include/tools/datetime.hxx index 7e2756ff730b..8d224dd73633 100644 --- a/include/tools/datetime.hxx +++ b/include/tools/datetime.hxx @@ -81,9 +81,9 @@ public: void ConvertToLocalTime() { *this += Time::GetUTCOffset(); } DateTime& operator +=( sal_Int32 nDays ) - { Date::operator+=( nDays ); return *this; } + { AddDays( nDays ); return *this; } DateTime& operator -=( sal_Int32 nDays ) - { Date::operator-=( nDays ); return *this; } + { AddDays( -nDays ); return *this; } DateTime& operator +=( double fTimeInDays ); DateTime& operator -=( double fTimeInDays ) { return operator+=( -fTimeInDays ); } 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<sal_Int32>(::rtl::math::approxFloor(nVal)); Date aCellDate = pFormatter->GetNullDate(); - aCellDate += static_cast<sal_Int32>(::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<sal_Int32>(::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<sal_Int32>(nVal); + aDate1.AddDays(nVal); Date aDate2 = aNullDate; nVal = GetValue(nCol+nAddX, nRow+nAddY); - aDate2 += static_cast<sal_Int32>(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<sal_Int32>(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<sal_Int32>(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<sal_Int32>(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<sal_Int32>(fStartVal); + aStartDate.AddDays(fStartVal); Date aEndDate = rNullDate; - aEndDate += static_cast<sal_Int32>(fInputEndVal); + aEndDate.AddDays(fInputEndVal); double fTempDate=0; if(aStartDate.GetYear()!=aEndDate.GetYear()) diff --git a/sfx2/source/doc/oleprops.cxx b/sfx2/source/doc/oleprops.cxx index d5e7348a8945..7c34acc49f35 100644 --- a/sfx2/source/doc/oleprops.cxx +++ b/sfx2/source/doc/oleprops.cxx @@ -574,7 +574,7 @@ void SfxOleDateProperty::ImplLoad( SvStream& rStrm ) //stored as number of days (not seconds) since December 31, 1899 ::Date aDate(31, 12, 1899); long nDays = fValue; - aDate += nDays; + aDate.AddDays( nDays ); maDate.Day = aDate.GetDay(); maDate.Month = aDate.GetMonth(); maDate.Year = aDate.GetYear(); diff --git a/svtools/source/control/calendar.cxx b/svtools/source/control/calendar.cxx index f79174303bd5..562b0030b9fb 100644 --- a/svtools/source/control/calendar.cxx +++ b/svtools/source/control/calendar.cxx @@ -418,7 +418,7 @@ void Calendar::ImplFormat() maFirstDate = aTempDate; nWeekDay = (sal_uInt16)aTempDate.GetDayOfWeek(); nWeekDay = (nWeekDay+(7-(sal_uInt16)eStartDay)) % 7; - maFirstDate -= static_cast<sal_Int32>(nWeekDay); + maFirstDate.AddDays( -nWeekDay ); mnDayCount = nWeekDay; sal_uInt16 nDaysInMonth; sal_uInt16 nMonthCount = (sal_uInt16)(mnMonthPerLine*mnLines); @@ -426,12 +426,12 @@ void Calendar::ImplFormat() { nDaysInMonth = aTempDate.GetDaysInMonth(); mnDayCount += nDaysInMonth; - aTempDate += nDaysInMonth; + aTempDate.AddDays( nDaysInMonth ); } Date aTempDate2 = aTempDate; --aTempDate2; nDaysInMonth = aTempDate2.GetDaysInMonth(); - aTempDate2 -= nDaysInMonth-1; + aTempDate2.AddDays( -(nDaysInMonth-1) ); nWeekDay = (sal_uInt16)aTempDate2.GetDayOfWeek(); nWeekDay = (nWeekDay+(7-(sal_uInt16)eStartDay)) % 7; mnDayCount += 42-nDaysInMonth-nWeekDay; @@ -484,7 +484,7 @@ sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const long nY; long nOffX; - sal_uInt16 nDay; + sal_Int32 nDay; DayOfWeek eStartDay = ImplGetWeekStart(); rDate = GetFirstMonth(); @@ -515,12 +515,12 @@ sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const long nDayY = nY+mnDaysOffY; if ( rPos.Y() < nDayY ) return 0; - sal_uInt16 nDayIndex = (sal_uInt16)rDate.GetDayOfWeek(); - nDayIndex = (nDayIndex+(7-(sal_uInt16)eStartDay)) % 7; + sal_Int32 nDayIndex = (sal_Int32)rDate.GetDayOfWeek(); + nDayIndex = (nDayIndex+(7-(sal_Int32)eStartDay)) % 7; if ( (i == 0) && (j == 0) ) { Date aTempDate = rDate; - aTempDate -= nDayIndex; + aTempDate.AddDays( -nDayIndex ); for ( nDay = 0; nDay < nDayIndex; nDay++ ) { nOffX = nDayX + (nDay*mnDayWidth); @@ -528,7 +528,7 @@ sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const (rPos.X() >= nOffX) && (rPos.X() < nOffX+mnDayWidth) ) { rDate = aTempDate; - rDate += nDay; + rDate.AddDays( nDay ); return CALENDAR_HITTEST_DAY; } } @@ -537,14 +537,14 @@ sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const { if ( rPos.Y() < nDayY ) { - rDate += nDayIndex; + rDate.AddDays( nDayIndex ); return 0; } nOffX = nDayX + (nDayIndex*mnDayWidth); if ( (rPos.Y() >= nDayY) && (rPos.Y() < nDayY+mnDayHeight) && (rPos.X() >= nOffX) && (rPos.X() < nOffX+mnDayWidth) ) { - rDate += nDay-1; + rDate.AddDays( nDay-1 ); return CALENDAR_HITTEST_DAY; } if ( nDayIndex == 6 ) @@ -559,14 +559,14 @@ sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const { sal_uInt16 nWeekDay = (sal_uInt16)rDate.GetDayOfWeek(); nWeekDay = (nWeekDay+(7-(sal_uInt16)eStartDay)) % 7; - sal_uInt16 nDayCount = 42-nDaysInMonth-nWeekDay; + sal_Int32 nDayCount = 42-nDaysInMonth-nWeekDay; Date aTempDate = rDate; - aTempDate += nDaysInMonth; + aTempDate.AddDays( nDaysInMonth ); for ( nDay = 1; nDay <= nDayCount; nDay++ ) { if ( rPos.Y() < nDayY ) { - rDate += nDayIndex; + rDate.AddDays( nDayIndex ); return 0; } nOffX = nDayX + (nDayIndex*mnDayWidth); @@ -574,7 +574,7 @@ sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const (rPos.X() >= nOffX) && (rPos.X() < nOffX+mnDayWidth) ) { rDate = aTempDate; - rDate += nDay-1; + rDate.AddDays( nDay-1 ); return CALENDAR_HITTEST_DAY; } if ( nDayIndex == 6 ) @@ -589,7 +589,7 @@ sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const } } - rDate += nDaysInMonth; + rDate.AddDays( nDaysInMonth ); nX += mnMonthWidth; } @@ -905,7 +905,7 @@ void Calendar::ImplDraw(vcl::RenderContext& rRenderContext) if (i == 0 && j == 0) { Date aTempDate = aDate; - aTempDate -= nDayIndex; + aTempDate.AddDays( -nDayIndex ); for (nDay = 0; nDay < nDayIndex; ++nDay) { nDeltaX = nDayX + (nDay * mnDayWidth); @@ -934,7 +934,7 @@ void Calendar::ImplDraw(vcl::RenderContext& rRenderContext) nWeekDay = (nWeekDay + (7 - (sal_uInt16)eStartDay)) % 7; sal_uInt16 nDayCount = 42 - nDaysInMonth - nWeekDay; Date aTempDate = aDate; - aTempDate += nDaysInMonth; + aTempDate.AddDays( nDaysInMonth ); for (nDay = 1; nDay <= nDayCount; ++nDay) { nDeltaX = nDayX + (nDayIndex * mnDayWidth); @@ -952,7 +952,7 @@ void Calendar::ImplDraw(vcl::RenderContext& rRenderContext) } } - aDate += nDaysInMonth; + aDate.AddDays( nDaysInMonth ); nX += mnMonthWidth; } @@ -1137,10 +1137,10 @@ void Calendar::ImplScroll( bool bPrev ) if ( bPrev ) { --aNewFirstMonth; - aNewFirstMonth -= aNewFirstMonth.GetDaysInMonth()-1; + aNewFirstMonth.AddDays( -(aNewFirstMonth.GetDaysInMonth()-1)); } else - aNewFirstMonth += aNewFirstMonth.GetDaysInMonth(); + aNewFirstMonth.AddDays( aNewFirstMonth.GetDaysInMonth()); SetFirstDate( aNewFirstMonth ); } @@ -1395,23 +1395,23 @@ void Calendar::KeyInput( const KeyEvent& rKEvt ) break; case KEY_UP: - aNewDate -= 7; + aNewDate.AddDays( -7 ); break; case KEY_DOWN: - aNewDate += 7; + aNewDate.AddDays( 7 ); break; case KEY_PAGEUP: { Date aTempDate = aNewDate; - aTempDate -= aNewDate.GetDay()+1; - aNewDate -= aTempDate.GetDaysInMonth(); + aTempDate.AddDays( -(aNewDate.GetDay()+1) ); + aNewDate.AddDays( -aTempDate.GetDaysInMonth() ); } break; case KEY_PAGEDOWN: - aNewDate += aNewDate.GetDaysInMonth(); + aNewDate.AddDays( aNewDate.GetDaysInMonth() ); break; case KEY_SPACE: @@ -1689,13 +1689,13 @@ void Calendar::SetCurDate( const Date& rNewDate ) if ( nDateOff < 365 ) { Date aFirstDate = GetFirstMonth(); - aFirstDate += aFirstDate.GetDaysInMonth(); + aFirstDate.AddDays( aFirstDate.GetDaysInMonth() ); ++aTempDate; while ( nDateOff > aTempDate.GetDaysInMonth() ) { - aFirstDate += aFirstDate.GetDaysInMonth(); + aFirstDate.AddDays( aFirstDate.GetDaysInMonth() ); sal_Int32 nDaysInMonth = aTempDate.GetDaysInMonth(); - aTempDate += nDaysInMonth; + aTempDate.AddDays( nDaysInMonth ); nDateOff -= nDaysInMonth; } SetFirstDate( aFirstDate ); @@ -1743,7 +1743,7 @@ Date Calendar::GetLastMonth() const Date aDate = GetFirstMonth(); sal_uInt16 nMonthCount = GetMonthCount(); for ( sal_uInt16 i = 0; i < nMonthCount; i++ ) - aDate += aDate.GetDaysInMonth(); + aDate.AddDays( aDate.GetDaysInMonth() ); --aDate; return aDate; } @@ -1796,9 +1796,9 @@ tools::Rectangle Calendar::GetDateRect( const Date& rDate ) const Date aLastDate = GetLastMonth(); if ( rDate > aLastDate ) { - sal_uInt16 nWeekDay = (sal_uInt16)aLastDate.GetDayOfWeek(); - nWeekDay = (nWeekDay+(7-(sal_uInt16)ImplGetWeekStart())) % 7; - aLastDate -= nWeekDay; + sal_Int32 nWeekDay = (sal_Int32)aLastDate.GetDayOfWeek(); + nWeekDay = (nWeekDay+(7-ImplGetWeekStart())) % 7; + aLastDate.AddDays( nWeekDay ); aRect = GetDateRect( aLastDate ); nDaysOff = rDate-aLastDate; nDayIndex = 0; @@ -1859,7 +1859,7 @@ tools::Rectangle Calendar::GetDateRect( const Date& rDate ) const } } - aDate += nDaysInMonth; + aDate.AddDays( nDaysInMonth ); nX += mnMonthWidth; } diff --git a/tools/qa/cppunit/test_date.cxx b/tools/qa/cppunit/test_date.cxx index 4f36baa07564..74d37efe5201 100644 --- a/tools/qa/cppunit/test_date.cxx +++ b/tools/qa/cppunit/test_date.cxx @@ -39,9 +39,11 @@ void DateTest::testDate() CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(1), aCE - aBCE); CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(-1), aBCE - aCE); aDate = aBCE; - CPPUNIT_ASSERT_EQUAL( aCE.GetDate(), (aDate += 1).GetDate()); + aDate.AddDays(1); + CPPUNIT_ASSERT_EQUAL( aCE.GetDate(), aDate.GetDate()); aDate = aCE; - CPPUNIT_ASSERT_EQUAL( aBCE.GetDate(), (aDate -= 1).GetDate()); + aDate.AddDays(-1); + CPPUNIT_ASSERT_EQUAL( aBCE.GetDate(), aDate.GetDate()); // The entire BCE and CE ranges cover that many days. Day 0 is -0001-12-31 CPPUNIT_ASSERT_EQUAL( kMaxDays, aMax - aBCE); @@ -49,13 +51,17 @@ void DateTest::testDate() // Truncate at limits, not under-/overflow or wrap. aDate = aMin; - CPPUNIT_ASSERT_EQUAL( aMin.GetDate(), (aDate -= 1).GetDate()); + aDate.AddDays(-1); + CPPUNIT_ASSERT_EQUAL( aMin.GetDate(), aDate.GetDate()); aDate = aMax; - CPPUNIT_ASSERT_EQUAL( aMax.GetDate(), (aDate += 1).GetDate()); + aDate.AddDays(1); + CPPUNIT_ASSERT_EQUAL( aMax.GetDate(), aDate.GetDate()); aDate = aBCE; - CPPUNIT_ASSERT_EQUAL( aMin.GetDate(), (aDate += (kMinDays-10)).GetDate()); + aDate.AddDays(kMinDays-10); + CPPUNIT_ASSERT_EQUAL( aMin.GetDate(), aDate.GetDate()); aDate = aBCE; - CPPUNIT_ASSERT_EQUAL( aMax.GetDate(), (aDate += (kMaxDays+10)).GetDate()); + aDate.AddDays(kMaxDays+10); + CPPUNIT_ASSERT_EQUAL( aMax.GetDate(), aDate.GetDate()); aDate = aMax; aDate.SetDay(32); aDate.Normalize(); @@ -109,14 +115,18 @@ void DateTest::testDate() // Year -1 is a leap year. aDate = Date(28,2,-1); - CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), (aDate += 1).GetDate()); + aDate.AddDays(1); + CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), aDate.GetDate()); aDate = Date(1,3,-1); - CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), (aDate -= 1).GetDate()); + aDate.AddDays(-1); + CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), aDate.GetDate()); // Year -5 is a leap year. aDate = Date(28,2,-5); - CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), (aDate += 1).GetDate()); + aDate.AddDays(1); + CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), aDate.GetDate()); aDate = Date(1,3,-5); - CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), (aDate -= 1).GetDate()); + aDate.AddDays(-1); + CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), aDate.GetDate()); } CPPUNIT_TEST_SUITE_REGISTRATION(DateTest); diff --git a/tools/source/datetime/datetime.cxx b/tools/source/datetime/datetime.cxx index aa17d65796e6..b87fcdfe8efe 100644 --- a/tools/source/datetime/datetime.cxx +++ b/tools/source/datetime/datetime.cxx @@ -190,7 +190,7 @@ DateTime& DateTime::operator +=( double fTimeInDays ) fInt = ::rtl::math::approxFloor( fTimeInDays ); fFrac = fInt >= fTimeInDays ? 0.0 : fTimeInDays - fInt; } - Date::operator+=( sal_Int32(fInt) ); // full days + AddDays( sal_Int32(fInt) ); // full days if ( fFrac ) { tools::Time aTime(0); // default ctor calls system time, we don't need that @@ -268,7 +268,7 @@ DateTime DateTime::CreateFromWin32FileDateTime( sal_uInt32 rLower, sal_uInt32 rU Date aDate(1,1,1601); // (0xffffffffffffffff / a100nPerDay = 21350398) fits into sal_Int32 // (0x7fffffff = 2147483647) - aDate += static_cast<sal_Int32>(nDays); + aDate.AddDays(nDays); SAL_WARN_IF( aDate - Date(1,1,1601) != static_cast<sal_Int32>(nDays), "tools.datetime", "DateTime::CreateFromWin32FileDateTime - date truncated to max"); @@ -287,7 +287,7 @@ DateTime DateTime::CreateFromUnixTime(const double fSecondsSinceEpoch) const sal_Int32 nDays = static_cast <sal_Int32>(::rtl::math::approxFloor(fValue)); Date aDate (1, 1, 1970); - aDate += nDays; + aDate.AddDays(nDays); SAL_WARN_IF(aDate - Date(1, 1, 1970) != static_cast<sal_Int32>(nDays), "tools.datetime", "DateTime::CreateFromUnixTime - date truncated to max"); diff --git a/tools/source/datetime/tdate.cxx b/tools/source/datetime/tdate.cxx index 4206b13c2dd1..1829806b1be1 100644 --- a/tools/source/datetime/tdate.cxx +++ b/tools/source/datetime/tdate.cxx @@ -571,20 +571,10 @@ bool Date::Normalize( sal_uInt16 & rDay, sal_uInt16 & rMonth, sal_Int16 & rYear return true; } -Date& Date::operator +=( sal_Int32 nDays ) +void Date::AddDays( sal_Int32 nDays ) { if (nDays != 0) *this = lcl_DaysToDate( GetAsNormalizedDays() + nDays ); - - return *this; -} - -Date& Date::operator -=( sal_Int32 nDays ) -{ - if (nDays != 0) - *this = lcl_DaysToDate( GetAsNormalizedDays() - nDays ); - - return *this; } Date& Date::operator ++() @@ -602,14 +592,14 @@ Date& Date::operator --() Date operator +( const Date& rDate, sal_Int32 nDays ) { Date aDate( rDate ); - aDate += nDays; + aDate.AddDays( nDays ); return aDate; } Date operator -( const Date& rDate, sal_Int32 nDays ) { Date aDate( rDate ); - aDate -= nDays; + aDate.AddDays( -nDays ); return aDate; } diff --git a/xmloff/source/core/xmluconv.cxx b/xmloff/source/core/xmluconv.cxx index d65ad047c130..7aaa01c25d8e 100644 --- a/xmloff/source/core/xmluconv.cxx +++ b/xmloff/source/core/xmluconv.cxx @@ -321,7 +321,7 @@ void SvXMLUnitConverter::convertDateTime( OUStringBuffer& rBuffer, double fValue = fDateTime; sal_Int32 nValue = static_cast <sal_Int32> (::rtl::math::approxFloor (fValue)); Date aDate (aTempNullDate.Day, aTempNullDate.Month, aTempNullDate.Year); - aDate += nValue; + aDate.AddDays( nValue); fValue -= nValue; double fCount; if (nValue > 0) @@ -371,7 +371,7 @@ void SvXMLUnitConverter::convertDateTime( OUStringBuffer& rBuffer, if (fHoursValue >= 24.0) { fHoursValue -= 24.0; - aDate += 1; + aDate.AddDays(1); } } sal_Int16 nTempYear = aDate.GetYear(); |