[Libreoffice-commits] core.git: vcl/source
Eike Rathke (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jul 7 08:39:34 UTC 2021
vcl/source/control/field2.cxx | 74 +-----------------------------------------
1 file changed, 3 insertions(+), 71 deletions(-)
New commits:
commit 0d3ffda9615ad48679e61d606004de65154cdbfb
Author: Eike Rathke <erack at redhat.com>
AuthorDate: Wed Jul 7 00:22:15 2021 +0200
Commit: Eike Rathke <erack at redhat.com>
CommitDate: Wed Jul 7 10:38:57 2021 +0200
DateFormatter: use Date::AddDays(), AddMonths(), AddYears()
... that do all the checks and normalize.
Change-Id: Id3ffcf5146b25020ec808aa70240953d39328a82
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118540
Reviewed-by: Eike Rathke <erack at redhat.com>
Tested-by: Jenkins
diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx
index 64cc39dfb276..d73e2d8900c4 100644
--- a/vcl/source/control/field2.cxx
+++ b/vcl/source/control/field2.cxx
@@ -1594,87 +1594,19 @@ OUString DateFormatter::ImplGetDateAsText( const Date& rDate ) const
static void ImplDateIncrementDay( Date& rDate, bool bUp )
{
DateFormatter::ExpandCentury( rDate );
-
- if ( bUp )
- {
- if ( (rDate.GetDay() != 31) || (rDate.GetMonth() != 12) || (rDate.GetYear() != SAL_MAX_INT16) )
- ++rDate;
- }
- else
- {
- if ( (rDate.GetDay() != 1 ) || (rDate.GetMonth() != 1) || (rDate.GetYear() != SAL_MIN_INT16) )
- --rDate;
- }
+ rDate.AddDays( bUp ? 1 : -1 );
}
static void ImplDateIncrementMonth( Date& rDate, bool bUp )
{
DateFormatter::ExpandCentury( rDate );
-
- sal_uInt16 nMonth = rDate.GetMonth();
- sal_Int16 nYear = rDate.GetYear();
- if ( bUp )
- {
- if ( (nMonth == 12) && (nYear < SAL_MAX_INT16) )
- {
- rDate.SetMonth( 1 );
- rDate.SetYear( rDate.GetNextYear() );
- }
- else
- {
- if ( nMonth < 12 )
- rDate.SetMonth( nMonth + 1 );
- }
- }
- else
- {
- if ( (nMonth == 1) && (nYear > SAL_MIN_INT16) )
- {
- rDate.SetMonth( 12 );
- rDate.SetYear( rDate.GetPrevYear() );
- }
- else
- {
- if ( nMonth > 1 )
- rDate.SetMonth( nMonth - 1 );
- }
- }
-
- sal_uInt16 nDaysInMonth = Date::GetDaysInMonth( rDate.GetMonth(), rDate.GetYear());
- if ( rDate.GetDay() > nDaysInMonth )
- rDate.SetDay( nDaysInMonth );
+ rDate.AddMonths( bUp ? 1 : -1 );
}
static void ImplDateIncrementYear( Date& rDate, bool bUp )
{
DateFormatter::ExpandCentury( rDate );
-
- sal_Int16 nYear = rDate.GetYear();
- sal_uInt16 nMonth = rDate.GetMonth();
- if ( bUp )
- {
- if ( nYear < SAL_MAX_INT16 )
- rDate.SetYear( rDate.GetNextYear() );
- }
- else
- {
- if ( nYear > SAL_MIN_INT16 )
- rDate.SetYear( rDate.GetPrevYear() );
- }
- if (nMonth != 2)
- return;
-
- // Handle February 29 from leap year to non-leap year.
- sal_uInt16 nDay = rDate.GetDay();
- if (nDay > 28)
- {
- // The check would not be necessary if it was guaranteed that the
- // date was valid before and actually was a leap year,
- // de-/incrementing a leap year with 29 always results in 28.
- sal_uInt16 nDaysInMonth = Date::GetDaysInMonth( nMonth, rDate.GetYear());
- if (nDay > nDaysInMonth)
- rDate.SetDay( nDaysInMonth);
- }
+ rDate.AddYears( bUp ? 1 : -1 );
}
bool DateFormatter::ImplAllowMalformedInput() const
More information about the Libreoffice-commits
mailing list