diff options
author | Eike Rathke <erack@redhat.com> | 2023-05-27 23:14:30 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2023-05-28 03:49:55 +0200 |
commit | 7e3ddf1e5aae5e4e956495e3d86a8cbf6e251b5e (patch) | |
tree | 77a821942e11545a9f7da6592a641ab1c8cfe4d4 /tools | |
parent | 20873f073ae4a9478f0a84355f779a2176bd2ec8 (diff) |
Factor out DateTime::NormalizeTimeRemainderAndApply(tools::Time& rTime)
Change-Id: Ie520b10baaeb4c94973c44435c3241e5d2254968
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152345
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'tools')
-rw-r--r-- | tools/source/datetime/datetime.cxx | 48 |
1 files changed, 15 insertions, 33 deletions
diff --git a/tools/source/datetime/datetime.cxx b/tools/source/datetime/datetime.cxx index efdb928986c3..47dc0555bc87 100644 --- a/tools/source/datetime/datetime.cxx +++ b/tools/source/datetime/datetime.cxx @@ -94,33 +94,37 @@ sal_Int64 DateTime::GetSecFromDateTime( const Date& rDate ) const } } -DateTime& DateTime::operator +=( const tools::Time& rTime ) +void DateTime::NormalizeTimeRemainderAndApply( tools::Time& rTime ) { - tools::Time aTime = *this; - aTime += rTime; - sal_uInt16 nHours = aTime.GetHour(); - if ( aTime.GetTime() > 0 ) + sal_uInt16 nHours = rTime.GetHour(); + if ( rTime.GetTime() > 0 ) { if (nHours >= 24) { AddDays( nHours / 24 ); nHours %= 24; - aTime.SetHour( nHours ); + rTime.SetHour( nHours ); } } - else if ( aTime.GetTime() != 0 ) + else if ( rTime.GetTime() != 0 ) { if (nHours >= 24) { AddDays( -static_cast<sal_Int32>(nHours) / 24 ); nHours %= 24; - aTime.SetHour( nHours ); + rTime.SetHour( nHours ); } Date::operator--(); - aTime = Time( 24, 0, 0 )+aTime; + rTime = Time( 24, 0, 0 ) + rTime; } - tools::Time::operator=( aTime ); + tools::Time::operator=( rTime ); +} +DateTime& DateTime::operator +=( const tools::Time& rTime ) +{ + tools::Time aTime = *this; + aTime += rTime; + NormalizeTimeRemainderAndApply(aTime); return *this; } @@ -128,29 +132,7 @@ DateTime& DateTime::operator -=( const tools::Time& rTime ) { tools::Time aTime = *this; aTime -= rTime; - sal_uInt16 nHours = aTime.GetHour(); - if ( aTime.GetTime() > 0 ) - { - if (nHours >= 24) - { - AddDays( nHours / 24 ); - nHours %= 24; - aTime.SetHour( nHours ); - } - } - else if ( aTime.GetTime() != 0 ) - { - if (nHours >= 24) - { - AddDays( -static_cast<sal_Int32>(nHours) / 24 ); - nHours %= 24; - aTime.SetHour( nHours ); - } - Date::operator--(); - aTime = Time( 24, 0, 0 )+aTime; - } - tools::Time::operator=( aTime ); - + NormalizeTimeRemainderAndApply(aTime); return *this; } |