diff options
-rw-r--r-- | sax/qa/cppunit/test_converter.cxx | 9 | ||||
-rw-r--r-- | sax/source/tools/converter.cxx | 19 | ||||
-rw-r--r-- | xmloff/source/core/xmluconv.cxx | 11 |
3 files changed, 31 insertions, 8 deletions
diff --git a/sax/qa/cppunit/test_converter.cxx b/sax/qa/cppunit/test_converter.cxx index 923c7eb2413e..17d1303e901c 100644 --- a/sax/qa/cppunit/test_converter.cxx +++ b/sax/qa/cppunit/test_converter.cxx @@ -215,8 +215,13 @@ void ConverterTest::testDateTime() doTest( util::DateTime(0, 0, 0, 24, 1, 1, 333) /*(0, 0, 0, 0, 2, 1, 333)*/, "0333-01-01T24:00:00"/*, "0333-01-02T00:00:00"*/ ); - doTestDateTimeF( "+0001-01-01T00:00:00" ); // invalid: ^+ - doTestDateTimeF( "1-01-01T00:00:00" ); // invalid: < 4 Y + // A leading ^+ is NOT invalid, ISO 8601 specifies this for explicit AD/CE. + doTest( util::DateTime(0, 0, 0, 0, 1, 1, 1), + "+0001-01-01T00:00:00", "0001-01-01T00:00:00" ); + // While ISO 8601 specifies a minimum of 4 year digits we are lenient in + // what we accept. + doTest( util::DateTime(0, 0, 0, 0, 1, 1, 1), + "1-01-01T00:00:00", "0001-01-01T00:00:00" ); doTestDateTimeF( "0001-1-01T00:00:00" ); // invalid: < 2 M doTestDateTimeF( "0001-01-1T00:00:00" ); // invalid: < 2 D doTestDateTimeF( "0001-01-01T0:00:00" ); // invalid: < 2 H diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx index b1629c8ec572..0c0779bac959 100644 --- a/sax/source/tools/converter.cxx +++ b/sax/source/tools/converter.cxx @@ -1345,15 +1345,26 @@ bool Converter::convertDateOrDateTime( const ::rtl::OUString string = rString.trim().toAsciiUpperCase(); sal_Int32 nPos(0); - if ((string.getLength() > nPos) && (sal_Unicode('-') == string[nPos])) + if (string.getLength() > nPos) { - //Negative Number - ++nPos; + if (sal_Unicode('-') == string[nPos]) + { + //Negative Number + ++nPos; + } + else if (sal_Unicode('+') == string[nPos]) + { + //Positive Number, explicit AD/CE + ++nPos; + } } sal_Int32 nYear(0); { - bSuccess = readDateTimeComponent(string, nPos, nYear, 4, false); + // While ISO 8601 specifies years with a minimum of 4 digits, be + // leninent in what we accept for years < 1000. One digit is acceptable + // if the remainders match. + bSuccess = readDateTimeComponent(string, nPos, nYear, 1, false); bSuccess &= (0 < nYear); bSuccess &= (nPos < string.getLength()); // not last token } diff --git a/xmloff/source/core/xmluconv.cxx b/xmloff/source/core/xmluconv.cxx index 5ea85f108975..6ceb8850b014 100644 --- a/xmloff/source/core/xmluconv.cxx +++ b/xmloff/source/core/xmluconv.cxx @@ -436,9 +436,16 @@ void SvXMLUnitConverter::convertDateTime( OUStringBuffer& rBuffer, aDate += 1; } } - rBuffer.append( sal_Int32( aDate.GetYear())); + sal_uInt16 nTemp = aDate.GetYear(); + if (nTemp < 1000) + rBuffer.append( sal_Unicode('0')); + if (nTemp < 100) + rBuffer.append( sal_Unicode('0')); + if (nTemp < 10) + rBuffer.append( sal_Unicode('0')); + rBuffer.append( sal_Int32( nTemp)); rBuffer.append( sal_Unicode('-')); - sal_uInt16 nTemp = aDate.GetMonth(); + nTemp = aDate.GetMonth(); if (nTemp < 10) rBuffer.append( sal_Unicode('0')); rBuffer.append( sal_Int32( nTemp)); |