[Libreoffice-commits] core.git: basic/source
Eike Rathke
erack at redhat.com
Wed May 3 14:13:52 UTC 2017
basic/source/runtime/methods.cxx | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
New commits:
commit e0eb3f5edd81ecdf1d2a36d9aad30c19420a9c35
Author: Eike Rathke <erack at redhat.com>
Date: Wed May 3 16:11:24 2017 +0200
CDateFromIso: accept YYMMDD two digit year for compatibility
Some may even rely on that..
Change-Id: Icdaf9b2917aa0b1ca5e76c5220022c65fc654d86
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index db6bc2b616cc..43548c05edb9 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -2048,6 +2048,7 @@ RTLFUNC(CDateToIso)
}
// Function to convert date from ISO 8601 date format YYYYMMDD or YYYY-MM-DD
+// And even YYMMDD for compatibility, sigh..
RTLFUNC(CDateFromIso)
{
(void)pBasic;
@@ -2062,7 +2063,7 @@ RTLFUNC(CDateFromIso)
break;
// Valid formats are
- // YYYYMMDD -YYYMMDD YYYYYMMDD -YYYYYMMDD
+ // YYYYMMDD -YYYMMDD YYYYYMMDD -YYYYYMMDD YYMMDD
// YYYY-MM-DD -YYYY-MM-DD YYYYY-MM-DD -YYYYY-MM-DD
sal_Int32 nSign = 1;
@@ -2073,20 +2074,27 @@ RTLFUNC(CDateFromIso)
}
const sal_Int32 nLen = aStr.getLength();
+ // Signed YYMMDD two digit year is invalid.
+ if (nLen == 6 && nSign == -1)
+ break;
+
// Now valid
- // YYYYMMDD YYYYYMMDD
+ // YYYYMMDD YYYYYMMDD YYMMDD
// YYYY-MM-DD YYYYY-MM-DD
- if (nLen < 8 || 11 < nLen)
+ if (nLen != 6 && (nLen < 8 || 11 < nLen))
break;
+ bool bUseTwoDigitYear = false;
OUString aYearStr, aMonthStr, aDayStr;
- if (nLen == 8 || nLen == 9)
+ if (nLen == 6 || nLen == 8 || nLen == 9)
{
- // (Y)YYYYMMDD
+ // ((Y)YY)YYMMDD
if (!comphelper::string::isdigitAsciiString(aStr))
break;
- const sal_Int32 nMonthPos = (nLen == 9 ? 5 : 4);
+ const sal_Int32 nMonthPos = (nLen == 6 ? 2 : (nLen == 9 ? 5 : 4));
+ if (nMonthPos == 2)
+ bUseTwoDigitYear = true;
aYearStr = aStr.copy( 0, nMonthPos );
aMonthStr = aStr.copy( nMonthPos, 2 );
aDayStr = aStr.copy( nMonthPos + 2, 2 );
@@ -2111,7 +2119,7 @@ RTLFUNC(CDateFromIso)
double dDate;
if (!implDateSerial( (sal_Int16)(nSign * aYearStr.toInt32()),
- (sal_Int16)aMonthStr.toInt32(), (sal_Int16)aDayStr.toInt32(), false, false, dDate ))
+ (sal_Int16)aMonthStr.toInt32(), (sal_Int16)aDayStr.toInt32(), bUseTwoDigitYear, false, dDate ))
break;
rPar.Get(0)->PutDate( dDate );
More information about the Libreoffice-commits
mailing list