summaryrefslogtreecommitdiff
path: root/tools/source
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2013-05-17 14:04:34 +0200
committerEike Rathke <erack@redhat.com>2013-05-17 14:13:36 +0200
commitcd9d1bdf5e3351c929d5b651c009ee17b4d962c4 (patch)
tree6f7dacb40a5c24f736ce1a3765ce0db791a88b35 /tools/source
parent5573ee341b1fc38d26fcfabffbfb23eb3cadea68 (diff)
resolved fdo#63805 max day of month of the intended month
Since 6619955e72c1c2f29a32e82478d19147c0d7610a Date::GetDaysInMonth() operates on the normalized value that corresponds to the actual values set at the Date instance, obtain and set number of days for the intended month instead of using the rolled-over date. Change-Id: Ia6b007675104f8e134b278f216c3bb48b72f061c
Diffstat (limited to 'tools/source')
-rw-r--r--tools/source/datetime/tdate.cxx29
1 files changed, 20 insertions, 9 deletions
diff --git a/tools/source/datetime/tdate.cxx b/tools/source/datetime/tdate.cxx
index 038a702da753..a07ee4e9ae31 100644
--- a/tools/source/datetime/tdate.cxx
+++ b/tools/source/datetime/tdate.cxx
@@ -44,7 +44,7 @@ inline sal_Bool ImpIsLeapYear( sal_uInt16 nYear )
}
// All callers must have sanitized or normalized month and year values!
-inline sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear )
+inline sal_uInt16 ImplDaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear )
{
if ( nMonth != 2 )
return aDaysInMonth[nMonth-1];
@@ -57,6 +57,17 @@ inline sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear )
}
}
+// static
+sal_uInt16 Date::GetDaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear )
+{
+ SAL_WARN_IF( nMonth < 1 || 12 < nMonth, "tools", "Date::GetDaysInMonth - nMonth out of bounds " << nMonth);
+ if (nMonth < 1)
+ nMonth = 1;
+ else if (12 < nMonth)
+ nMonth = 12;
+ return ImplDaysInMonth( nMonth, nYear);
+}
+
long Date::DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear )
{
long nDays;
@@ -66,7 +77,7 @@ long Date::DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear )
nDays = ((sal_uIntPtr)nYear-1) * 365;
nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400);
for( sal_uInt16 i = 1; i < nMonth; i++ )
- nDays += DaysInMonth(i,nYear);
+ nDays += ImplDaysInMonth(i,nYear);
nDays += nDay;
return nDays;
}
@@ -105,9 +116,9 @@ static void DaysToDate( long nDays,
while ( bCalc );
rMonth = 1;
- while ( (sal_uIntPtr)nTempDays > DaysInMonth( rMonth, rYear ) )
+ while ( (sal_uIntPtr)nTempDays > ImplDaysInMonth( rMonth, rYear ) )
{
- nTempDays -= DaysInMonth( rMonth, rYear );
+ nTempDays -= ImplDaysInMonth( rMonth, rYear );
rMonth++;
}
rDay = (sal_uInt16)nTempDays;
@@ -179,7 +190,7 @@ sal_uInt16 Date::GetDayOfYear() const
Normalize( nDay, nMonth, nYear);
for( sal_uInt16 i = 1; i < nMonth; i++ )
- nDay = nDay + ::DaysInMonth( i, nYear ); // += yields a warning on MSVC, so don't use it
+ nDay = nDay + ::ImplDaysInMonth( i, nYear ); // += yields a warning on MSVC, so don't use it
return nDay;
}
@@ -279,7 +290,7 @@ sal_uInt16 Date::GetDaysInMonth() const
sal_uInt16 nYear = GetYear();
Normalize( nDay, nMonth, nYear);
- return DaysInMonth( nMonth, nYear );
+ return ImplDaysInMonth( nMonth, nYear );
}
sal_Bool Date::IsLeapYear() const
@@ -296,7 +307,7 @@ sal_Bool Date::IsValidAndGregorian() const
if ( !nMonth || (nMonth > 12) )
return sal_False;
- if ( !nDay || (nDay > DaysInMonth( nMonth, nYear )) )
+ if ( !nDay || (nDay > ImplDaysInMonth( nMonth, nYear )) )
return sal_False;
else if ( nYear <= 1582 )
{
@@ -321,7 +332,7 @@ bool Date::IsValidDate( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear )
{
if ( !nMonth || (nMonth > 12) )
return false;
- if ( !nDay || (nDay > DaysInMonth( nMonth, nYear )) )
+ if ( !nDay || (nDay > ImplDaysInMonth( nMonth, nYear )) )
return false;
return true;
}
@@ -371,7 +382,7 @@ bool Date::Normalize( sal_uInt16 & rDay, sal_uInt16 & rMonth, sal_uInt16 & rYear
}
}
sal_uInt16 nDays;
- while (rDay > (nDays = DaysInMonth( rMonth, rYear)))
+ while (rDay > (nDays = ImplDaysInMonth( rMonth, rYear)))
{
rDay -= nDays;
if (rMonth < 12)