diff options
author | Eike Rathke <erack@redhat.com> | 2017-05-03 16:11:24 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-05-03 16:13:21 +0200 |
commit | e0eb3f5edd81ecdf1d2a36d9aad30c19420a9c35 (patch) | |
tree | e813759fe6fd27562b07f3913feda4a3fb256f2e /basic | |
parent | 751d431f881f52dee6e0fbcfb8308dbf2127999c (diff) |
CDateFromIso: accept YYMMDD two digit year for compatibility
Some may even rely on that..
Change-Id: Icdaf9b2917aa0b1ca5e76c5220022c65fc654d86
Diffstat (limited to 'basic')
-rw-r--r-- | basic/source/runtime/methods.cxx | 22 |
1 files changed, 15 insertions, 7 deletions
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 ); |