summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2022-05-19 13:23:33 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2022-05-20 10:42:31 +0200
commit712b7e578292e521c64e6de117dbf7d11e38ba7a (patch)
treed7d85b1c0fc50527c8f4cb61d0ea50d32339dc40
parentcd733032151e0e06a49680edc180e695f2ca21ee (diff)
svl: SvNumberformat::GetMappedFormatstring() vs. LANGUAGE_DONTKNOW
There is this number format: <number:date-style style:name="N36" number:automatic-order="true"> <number:day number:style="long"/> <number:text>.</number:text> <number:month number:style="long"/> <number:text>.</number:text> <number:year number:style="long"/> </number:date-style> MSWordExportBase::GetNumberFormat() exports as: DATE \@"dd/MM/yyyy" But should be: DATE \@"dd.MM.yyyy" The problem is that with LANGUAGE_DONTKNOW, the available LocaleDataWrapper can't be considered reliable, so prefer to use the existing separator string in this case. Change-Id: I596bea5daa75c717931b3c5d5506103b87b8ee08
-rw-r--r--svl/qa/unit/svl.cxx16
-rw-r--r--svl/source/numbers/zformat.cxx9
2 files changed, 23 insertions, 2 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index d30a7b6279ec..2e4f21099d0d 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -34,6 +34,7 @@
#include <svl/sharedstring.hxx>
#include <tools/color.hxx>
#include <unotools/syslocale.hxx>
+#include <unotest/bootstrapfixturebase.hxx> // for CPPUNIT_TEST_FIXTURE
#include <memory>
#include <unicode/timezone.h>
@@ -90,7 +91,7 @@ public:
CPPUNIT_TEST(testExcelExportFormats);
CPPUNIT_TEST_SUITE_END();
-private:
+protected:
uno::Reference< uno::XComponentContext > m_xContext;
void checkPreviewString(SvNumberFormatter& aFormatter,
const OUString& sCode,
@@ -1728,6 +1729,19 @@ void Test::testExcelExportFormats()
CPPUNIT_ASSERT_EQUAL( OUString("[$R-1C09]\\ #,##0.0;[$R-1C09]\\-#,##0.0"), aCode);
}
+CPPUNIT_TEST_FIXTURE(Test, testLanguageDontknow)
+{
+ SvNumberFormatter aFormatter(m_xContext, LANGUAGE_ENGLISH_US);
+ NfKeywordTable keywords;
+ aFormatter.FillKeywordTableForExcel(keywords);
+ OUString code("TT.MM.JJJJ");
+ sal_uInt32 nKey = aFormatter.GetEntryKey(code, LANGUAGE_GERMAN);
+ CPPUNIT_ASSERT(nKey != NUMBERFORMAT_ENTRY_NOT_FOUND);
+ SvNumberformat const*const pFormat = aFormatter.GetEntry(nKey);
+ LocaleDataWrapper ldw(m_xContext, LanguageTag(LANGUAGE_DONTKNOW));
+ CPPUNIT_ASSERT_EQUAL(OUString("dd.mm.yyyy"), pFormat->GetMappedFormatstring(keywords, ldw));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 23c0919aecf2..acbea945cd88 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -5291,7 +5291,14 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords,
aStr.append( "-" );
break;
case NF_SYMBOLTYPE_DATESEP :
- aStr.append( rLocWrp.getDateSep() );
+ if (nOriginalLang == LANGUAGE_DONTKNOW)
+ { // prefer whatever the existing separator is
+ aStr.append(rStrArray[j]);
+ }
+ else
+ {
+ aStr.append( rLocWrp.getDateSep() );
+ }
break;
case NF_SYMBOLTYPE_TIMESEP :
aStr.append( rLocWrp.getTimeSep() );