From 252aab1b9dc1dbeace3087929a52e1248f043839 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Fri, 21 Jul 2017 13:32:10 +0200 Subject: Eliminate DateTime::operator+=() and -=() with POD types And make some tools::Time conversion ctors explicit to catch more oddities like automatic conversion from sal_Int64 that might be unintentional. Change-Id: If275297d86d6657544c056a712b862523e310e44 Reviewed-on: https://gerrit.libreoffice.org/40275 Tested-by: Jenkins Reviewed-by: Eike Rathke --- extensions/source/propctrlr/standardcontrol.cxx | 4 ++-- include/tools/datetime.hxx | 8 +------- include/tools/time.hxx | 8 ++++---- sc/source/filter/excel/xlroot.cxx | 2 +- sfx2/source/doc/objcont.cxx | 2 +- sw/inc/docufld.hxx | 2 +- sw/source/core/fields/flddat.cxx | 4 ++-- sw/source/uibase/docvw/AnnotationWin2.cxx | 2 +- tools/source/datetime/datetime.cxx | 9 ++++----- writerfilter/source/dmapper/DomainMapper_Impl.cxx | 4 ++-- xmlsecurity/source/dialogs/certificateviewer.cxx | 4 ++-- 11 files changed, 21 insertions(+), 28 deletions(-) diff --git a/extensions/source/propctrlr/standardcontrol.cxx b/extensions/source/propctrlr/standardcontrol.cxx index 8381a7abad88..f566a8483eb5 100644 --- a/extensions/source/propctrlr/standardcontrol.cxx +++ b/extensions/source/propctrlr/standardcontrol.cxx @@ -298,13 +298,13 @@ namespace pcr // add the "days" part double nDays = floor( nValue ); - aDateTime += nDays; + aDateTime.AddDays( nDays ); // add the "time" part double nTime = nValue - nDays; nTime = ::rtl::math::round( nTime * 86400.0 ) / 86400.0; // we're not interested in 100th seconds, and this here prevents rounding errors - aDateTime += nTime; + aDateTime.AddTime( nTime ); util::DateTime aUNODateTime; ::utl::typeConvert( aDateTime, aUNODateTime ); diff --git a/include/tools/datetime.hxx b/include/tools/datetime.hxx index 8d224dd73633..fd48e2314c27 100644 --- a/include/tools/datetime.hxx +++ b/include/tools/datetime.hxx @@ -80,13 +80,7 @@ public: void ConvertToUTC() { *this -= Time::GetUTCOffset(); } void ConvertToLocalTime() { *this += Time::GetUTCOffset(); } - DateTime& operator +=( sal_Int32 nDays ) - { AddDays( nDays ); return *this; } - DateTime& operator -=( sal_Int32 nDays ) - { AddDays( -nDays ); return *this; } - DateTime& operator +=( double fTimeInDays ); - DateTime& operator -=( double fTimeInDays ) - { return operator+=( -fTimeInDays ); } + void AddTime( double fTimeInDays ); DateTime& operator +=( const tools::Time& rTime ); DateTime& operator -=( const tools::Time& rTime ); diff --git a/include/tools/time.hxx b/include/tools/time.hxx index 12f1e909c8ec..d8b4e6d06fc6 100644 --- a/include/tools/time.hxx +++ b/include/tools/time.hxx @@ -64,13 +64,13 @@ public: static const sal_Int64 nanoPerMilli = 1000000; static const sal_Int64 nanoPerCenti = 10000000; - Time( TimeInitEmpty ) + explicit Time( TimeInitEmpty ) { nTime = 0; } - Time( TimeInitSystem ); - Time( sal_Int64 _nTime ) { Time::nTime = _nTime; } + explicit Time( TimeInitSystem ); + explicit Time( sal_Int64 _nTime ) { Time::nTime = _nTime; } Time( const tools::Time& rTime ); Time( const css::util::Time& rTime ); - Time( const css::util::DateTime& rDateTime ); + explicit Time( const css::util::DateTime& rDateTime ); Time( sal_uInt32 nHour, sal_uInt32 nMin, sal_uInt32 nSec = 0, sal_uInt64 nNanoSec = 0 ); diff --git a/sc/source/filter/excel/xlroot.cxx b/sc/source/filter/excel/xlroot.cxx index 72b1450a5084..2e9588b6e769 100644 --- a/sc/source/filter/excel/xlroot.cxx +++ b/sc/source/filter/excel/xlroot.cxx @@ -339,7 +339,7 @@ DateTime XclRoot::GetDateTimeFromDouble( double fValue ) const DateTime aDateTime = GetNullDate() + fValue; // adjust dates before 1900-03-01 to get correct time values if( aDateTime < DateTime( Date( 1, 3, 1900 ) ) ) - aDateTime += sal_Int32(1); + aDateTime.AddDays(1); return aDateTime; } diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx index ef8425a224fd..41d8869d811e 100644 --- a/sfx2/source/doc/objcont.cxx +++ b/sfx2/source/doc/objcont.cxx @@ -259,7 +259,7 @@ void SfxObjectShell::UpdateTime_Impl( // If 1 or up to 31 days between now and last editing - calculate time indirectly. // nAddTime = (24h - nTime) + (nDays * 24h) + aNow --nDays; - nAddTime = nDays*n24Time.GetTime() ; + nAddTime = tools::Time( nDays * n24Time.GetTime()); nAddTime += n24Time-static_cast(pImpl->nTime); nAddTime += aNow ; } diff --git a/sw/inc/docufld.hxx b/sw/inc/docufld.hxx index 5cdeb3ff9030..440f31d306fb 100644 --- a/sw/inc/docufld.hxx +++ b/sw/inc/docufld.hxx @@ -465,7 +465,7 @@ public: const DateTime& GetDateTime() const { return aDateTime; } const Date GetDate() const { return Date(aDateTime.GetDate()); } - const tools::Time GetTime() const { return aDateTime.GetTime(); } + const tools::Time GetTime() const { return tools::Time(aDateTime.GetTime()); } sal_uInt32 GetPostItId() const { return m_nPostItId; } /// Author diff --git a/sw/source/core/fields/flddat.cxx b/sw/source/core/fields/flddat.cxx index 5ae5da51a9c3..a611e088eb36 100644 --- a/sw/source/core/fields/flddat.cxx +++ b/sw/source/core/fields/flddat.cxx @@ -152,8 +152,8 @@ tools::Time SwDateTimeField::GetTime() const { double fDummy; double fFract = modf(GetValue(), &fDummy); - DateTime aDT(Date(static_cast(fDummy)), 0); - aDT += fFract; + DateTime aDT(Date(static_cast(fDummy))); + aDT.AddTime(fFract); return static_cast(aDT); } diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx b/sw/source/uibase/docvw/AnnotationWin2.cxx index a43d402e3add..4fca14fae575 100644 --- a/sw/source/uibase/docvw/AnnotationWin2.cxx +++ b/sw/source/uibase/docvw/AnnotationWin2.cxx @@ -573,7 +573,7 @@ void SwAnnotationWin::CheckMetaText() { sMeta = SwResId(STR_NODATE); } - if (GetTime()!=0) + if (GetTime().GetTime()!=0) { sMeta += " " + rLocalData.getTime( GetTime(),false ); } diff --git a/tools/source/datetime/datetime.cxx b/tools/source/datetime/datetime.cxx index b87fcdfe8efe..999c98d4fee8 100644 --- a/tools/source/datetime/datetime.cxx +++ b/tools/source/datetime/datetime.cxx @@ -152,14 +152,14 @@ DateTime& DateTime::operator -=( const tools::Time& rTime ) DateTime operator +( const DateTime& rDateTime, sal_Int32 nDays ) { DateTime aDateTime( rDateTime ); - aDateTime += nDays; + aDateTime.AddDays( nDays ); return aDateTime; } DateTime operator -( const DateTime& rDateTime, sal_Int32 nDays ) { DateTime aDateTime( rDateTime ); - aDateTime -= nDays; + aDateTime.AddDays( -nDays ); return aDateTime; } @@ -177,7 +177,7 @@ DateTime operator -( const DateTime& rDateTime, const tools::Time& rTime ) return aDateTime; } -DateTime& DateTime::operator +=( double fTimeInDays ) +void DateTime::AddTime( double fTimeInDays ) { double fInt, fFrac; if ( fTimeInDays < 0.0 ) @@ -198,13 +198,12 @@ DateTime& DateTime::operator +=( double fTimeInDays ) aTime.MakeTimeFromNS( static_cast(fFrac) ); // method handles negative ns operator+=( aTime ); } - return *this; } DateTime operator +( const DateTime& rDateTime, double fTimeInDays ) { DateTime aDateTime( rDateTime ); - aDateTime += fTimeInDays; + aDateTime.AddTime( fTimeInDays ); return aDateTime; } diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 8011c65baa88..b9ae8738766b 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -4469,9 +4469,9 @@ static util::DateTime lcl_dateTimeFromSerial(const double& dSerial) const sal_uInt16 secondsPerHour = 3600; DateTime d(Date(30, 12, 1899)); - d += (sal_Int32)dSerial; + d.AddDays( static_cast(dSerial) ); - double frac = dSerial - (long)dSerial; + double frac = dSerial - static_cast(dSerial); sal_uInt32 seconds = frac * secondsPerDay; util::DateTime date; diff --git a/xmlsecurity/source/dialogs/certificateviewer.cxx b/xmlsecurity/source/dialogs/certificateviewer.cxx index 1b7d94b5bdd7..89a9e8fdabc2 100644 --- a/xmlsecurity/source/dialogs/certificateviewer.cxx +++ b/xmlsecurity/source/dialogs/certificateviewer.cxx @@ -277,12 +277,12 @@ CertificateViewerDetailsTP::CertificateViewerDetailsTP( vcl::Window* _pParent, C utl::typeConvert( xCert->getNotValidBefore(), aDateTime ); aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( Date( aDateTime.GetDate()) ); aLBEntry += " "; - aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() ); + aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( tools::Time( aDateTime.GetTime()) ); InsertElement( XsResId( STR_VALIDFROM ), aLBEntry, aLBEntry ); utl::typeConvert( xCert->getNotValidAfter(), aDateTime ); aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( Date( aDateTime.GetDate()) ); aLBEntry += " "; - aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() ); + aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( tools::Time( aDateTime.GetTime()) ); InsertElement( XsResId( STR_VALIDTO ), aLBEntry, aLBEntry ); std::pair< OUString, OUString > pairSubject = -- cgit