summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2013-06-29 17:16:07 +0200
committerMichael Stahl <mstahl@redhat.com>2013-06-29 18:31:25 +0200
commit56dc79822d5c464b33b1d0199558ca684e94c069 (patch)
tree90b8ca1bbf1a79786d60ec4c5c38d5c85c2833f9 /sax
parentcc8625f0083cd1a31da42ab8470ec4a50746fe1a (diff)
i#108348 sax::Converter: support negative date and dateTime
Change-Id: Ie2726c7ec941a5690e053d39212d7f516e2c27ba
Diffstat (limited to 'sax')
-rw-r--r--sax/qa/cppunit/test_converter.cxx6
-rw-r--r--sax/source/tools/converter.cxx22
2 files changed, 18 insertions, 10 deletions
diff --git a/sax/qa/cppunit/test_converter.cxx b/sax/qa/cppunit/test_converter.cxx
index 31e96bcf6cba..8a5f72826a92 100644
--- a/sax/qa/cppunit/test_converter.cxx
+++ b/sax/qa/cppunit/test_converter.cxx
@@ -192,8 +192,10 @@ void ConverterTest::testDateTime()
doTest( util::DateTime(0, 0, 0, 0, 1, 1, 1), "0001-01-01T00:00:00" );
doTest( util::DateTime(0, 0, 0, 0, 1, 1, 1),
"0001-01-01T00:00:00Z", "0001-01-01T00:00:00" );
-// doTest( util::DateTime(0, 0, 0, 0, 1, 1, -1), "-0001-01-01T00:00:00" );
-// doTest( util::DateTime(0, 0, 0, 0, 1, 1, -1), "-0001-01-01T00:00:00Z" );
+ doTest( util::DateTime(0, 0, 0, 0, 1, 1, -1), "-0001-01-01T00:00:00");
+// doTest( util::DateTime(0, 0, 0, 0, 1, 1, -1), "-0001-01-01T00:00:00Z");
+ doTest( util::DateTime(0, 0, 0, 0, 1, 1, -324),
+ "-0324-01-01T00:00:00" );
doTest( util::DateTime(0, 0, 0, 0, 1, 1, 1),
"0001-01-01T00:00:00-00:00", "0001-01-01T00:00:00" );
doTest( util::DateTime(0, 0, 0, 0, 1, 1, 1),
diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx
index 33a8257d23a6..690c3e581c51 100644
--- a/sax/source/tools/converter.cxx
+++ b/sax/source/tools/converter.cxx
@@ -1207,16 +1207,20 @@ void Converter::convertDateTime(
const sal_Unicode zero('0');
const sal_Unicode tee ('T');
- if (i_rDateTime.Year < 1000) {
+ sal_Int32 const nYear(abs(i_rDateTime.Year));
+ if (i_rDateTime.Year < 0) {
+ i_rBuffer.append(dash); // negative
+ }
+ if (nYear < 1000) {
i_rBuffer.append(zero);
}
- if (i_rDateTime.Year < 100) {
+ if (nYear < 100) {
i_rBuffer.append(zero);
}
- if (i_rDateTime.Year < 10) {
+ if (nYear < 10) {
i_rBuffer.append(zero);
}
- i_rBuffer.append( static_cast<sal_Int32>(i_rDateTime.Year) ).append(dash);
+ i_rBuffer.append(nYear).append(dash);
if( i_rDateTime.Month < 10 ) {
i_rBuffer.append(zero);
}
@@ -1330,6 +1334,7 @@ bool Converter::convertDateOrDateTime(
bool & rbDateTime, const OUString & rString )
{
bool bSuccess = true;
+ bool isNegative(false);
const OUString string = rString.trim().toAsciiUpperCase();
sal_Int32 nPos(0);
@@ -1337,7 +1342,7 @@ bool Converter::convertDateOrDateTime(
{
if (sal_Unicode('-') == string[nPos])
{
- //Negative Number
+ isNegative = true;
++nPos;
}
}
@@ -1530,8 +1535,8 @@ bool Converter::convertDateOrDateTime(
{
if (bHaveTime) // time is optional
{
- // util::DateTime does not support negative years!
- rDateTime.Year = static_cast<sal_uInt16>(nYear);
+ rDateTime.Year =
+ ((isNegative) ? (-1) : (+1)) * static_cast<sal_Int16>(nYear);
rDateTime.Month = static_cast<sal_uInt16>(nMonth);
rDateTime.Day = static_cast<sal_uInt16>(nDay);
rDateTime.Hours = static_cast<sal_uInt16>(nHours);
@@ -1542,7 +1547,8 @@ bool Converter::convertDateOrDateTime(
}
else
{
- rDate.Year = static_cast<sal_uInt16>(nYear);
+ rDate.Year =
+ ((isNegative) ? (-1) : (+1)) * static_cast<sal_Int16>(nYear);
rDate.Month = static_cast<sal_uInt16>(nMonth);
rDate.Day = static_cast<sal_uInt16>(nDay);
rbDateTime = false;