summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-11-23 17:03:21 +0100
committerCaolán McNamara <caolanm@redhat.com>2017-11-24 17:18:54 +0100
commit8be272b6642611e152ddc8e13f8570d2e673e0b4 (patch)
tree5163212738f6a33a97f390ed83f048af545372ff
parentf781a5faae6492de19589c20bd695b9cfe377d23 (diff)
tdf#114011 limit/truncate date, not only year
Change-Id: I479040f411fb8b5975c0aa1aa24f95c957cf80cf (cherry picked from commit db080dad6c9ad9930e26aeb70638d7146afa279a) Reviewed-on: https://gerrit.libreoffice.org/45172 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--basic/source/runtime/methods1.cxx27
1 files changed, 19 insertions, 8 deletions
diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index f3502fe3465a..bf3b5e8e3dc3 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -2018,17 +2018,26 @@ inline void implGetDayMonthYear( sal_Int16& rnYear, sal_Int16& rnMonth, sal_Int1
rnYear = implGetDateYear( dDate );
}
-inline sal_Int16 limitToINT16( sal_Int32 n32 )
+/** Limits a date to valid dates within tools' class Date capabilities.
+
+ @return the year number, truncated if necessary and in that case also
+ rMonth and rDay adjusted.
+ */
+inline sal_Int16 limitDate( sal_Int32 n32Year, sal_Int16& rMonth, sal_Int16& rDay )
{
- if( n32 > 32767 )
+ if( n32Year > SAL_MAX_INT16 )
{
- n32 = 32767;
+ n32Year = SAL_MAX_INT16;
+ rMonth = 12;
+ rDay = 31;
}
- else if( n32 < -32768 )
+ else if( n32Year < SAL_MIN_INT16 )
{
- n32 = -32768;
+ n32Year = SAL_MIN_INT16;
+ rMonth = 1;
+ rDay = 1;
}
- return (sal_Int16)n32;
+ return (sal_Int16)n32Year;
}
RTLFUNC(DateAdd)
@@ -2073,7 +2082,8 @@ RTLFUNC(DateAdd)
case INTERVAL_YYYY:
{
sal_Int32 nTargetYear = lNumber + nYear;
- nTargetYear16 = limitToINT16( nTargetYear );
+ nTargetYear16 = limitDate( nTargetYear, nMonth, nDay );
+ /* TODO: should the result be error if the date was limited? It never was. */
nTargetMonth = nMonth;
bOk = implDateSerial( nTargetYear16, nTargetMonth, nDay, false, true, dNewDate );
break;
@@ -2118,7 +2128,8 @@ RTLFUNC(DateAdd)
}
nTargetYear = (sal_Int32)nYear + nYearsAdd;
}
- nTargetYear16 = limitToINT16( nTargetYear );
+ nTargetYear16 = limitDate( nTargetYear, nTargetMonth, nDay );
+ /* TODO: should the result be error if the date was limited? It never was. */
bOk = implDateSerial( nTargetYear16, nTargetMonth, nDay, false, true, dNewDate );
break;
}