diff options
author | Eike Rathke <erack@redhat.com> | 2023-05-18 23:30:51 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2023-05-19 02:29:18 +0200 |
commit | 261063e69e80193ad563e086c515fd6e22e48464 (patch) | |
tree | b1b81416b88bcf3618959d43834e3dc0a7a46ad9 | |
parent | e15f54ebe7eb53f9e5d5ae7de4449c7e27171daf (diff) |
Eliminate 24h loops in DateTime::operator+=/-=(tools::Time&)
... and repeated Date::operator++/--() that each calculate
lcl_DaysToDate( GetAsNormalizedDays() + 1 )
where Date::AddDays() does it once.
Also, that probably never worked correctly with negative time results >=24h
Change-Id: Ic67aaa3d93e0d6533501d52671acf765e2d9bbdd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151984
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
-rw-r--r-- | tools/source/datetime/datetime.cxx | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/tools/source/datetime/datetime.cxx b/tools/source/datetime/datetime.cxx index 00790ff78dd4..efdb928986c3 100644 --- a/tools/source/datetime/datetime.cxx +++ b/tools/source/datetime/datetime.cxx @@ -101,19 +101,20 @@ DateTime& DateTime::operator +=( const tools::Time& rTime ) sal_uInt16 nHours = aTime.GetHour(); if ( aTime.GetTime() > 0 ) { - while ( nHours >= 24 ) + if (nHours >= 24) { - Date::operator++(); - nHours -= 24; + AddDays( nHours / 24 ); + nHours %= 24; + aTime.SetHour( nHours ); } - aTime.SetHour( nHours ); } else if ( aTime.GetTime() != 0 ) { - while ( nHours >= 24 ) + if (nHours >= 24) { - Date::operator--(); - nHours -= 24; + AddDays( -static_cast<sal_Int32>(nHours) / 24 ); + nHours %= 24; + aTime.SetHour( nHours ); } Date::operator--(); aTime = Time( 24, 0, 0 )+aTime; @@ -130,19 +131,20 @@ DateTime& DateTime::operator -=( const tools::Time& rTime ) sal_uInt16 nHours = aTime.GetHour(); if ( aTime.GetTime() > 0 ) { - while ( nHours >= 24 ) + if (nHours >= 24) { - Date::operator++(); - nHours -= 24; + AddDays( nHours / 24 ); + nHours %= 24; + aTime.SetHour( nHours ); } - aTime.SetHour( nHours ); } else if ( aTime.GetTime() != 0 ) { - while ( nHours >= 24 ) + if (nHours >= 24) { - Date::operator--(); - nHours -= 24; + AddDays( -static_cast<sal_Int32>(nHours) / 24 ); + nHours %= 24; + aTime.SetHour( nHours ); } Date::operator--(); aTime = Time( 24, 0, 0 )+aTime; |