sc/qa/unit/data/xlsx/seconds-without-truncate-and-decimals.xlsx |binary sc/qa/unit/subsequent_export_test4.cxx | 18 +++++++--- svl/qa/unit/svl.cxx | 17 +++++++++ svl/source/numbers/zforscan.cxx | 6 +++ xmloff/source/style/xmlnumfe.cxx | 8 ++-- 5 files changed, 42 insertions(+), 7 deletions(-)
New commits: commit 6dd2ebbba23b20864d3cf74322540c628088375c Author: Laurent Balland <laurent.ball...@mailo.fr> AuthorDate: Tue May 16 09:24:55 2023 +0200 Commit: Eike Rathke <er...@redhat.com> CommitDate: Fri May 26 18:20:26 2023 +0200 tdf#150028 Treat decimal separator after [SS] Only decimal separator after S or SS was treated This change adds [S] and [SS] to treat formats like [SS].00 Update: correct export to XML Add QA unit tests Change-Id: I97ce4084d3caab2fcd18f1c70cd4221596290563 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151823 Tested-by: Jenkins Reviewed-by: Eike Rathke <er...@redhat.com> diff --git a/sc/qa/unit/data/xlsx/seconds-without-truncate-and-decimals.xlsx b/sc/qa/unit/data/xlsx/seconds-without-truncate-and-decimals.xlsx new file mode 100644 index 000000000000..a26b3630708e Binary files /dev/null and b/sc/qa/unit/data/xlsx/seconds-without-truncate-and-decimals.xlsx differ diff --git a/sc/qa/unit/subsequent_export_test4.cxx b/sc/qa/unit/subsequent_export_test4.cxx index 9d7dddc99c78..b34a8fcdadf6 100644 --- a/sc/qa/unit/subsequent_export_test4.cxx +++ b/sc/qa/unit/subsequent_export_test4.cxx @@ -1460,24 +1460,34 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf148820) namespace { -void lcl_TestEmbeddedTextInDecimal(ScDocument& rDoc) +void lcl_TestNumberFormat(ScDocument& rDoc, const OUString& rFormatStrOK) { sal_uInt32 nNumberFormat = rDoc.GetNumberFormat(0, 0, 0); const SvNumberformat* pNumberFormat = rDoc.GetFormatTable()->GetEntry(nNumberFormat); const OUString& rFormatStr = pNumberFormat->GetFormatstring(); - CPPUNIT_ASSERT_EQUAL(OUString("#,##0.000\" \"###\" \"###"), rFormatStr); + CPPUNIT_ASSERT_EQUAL(rFormatStrOK, rFormatStr); } } +CPPUNIT_TEST_FIXTURE(ScExportTest4, testSecondsWithoutTruncateAndDecimals) +{ + createScDoc("xlsx/seconds-without-truncate-and-decimals.xlsx"); + lcl_TestNumberFormat(*getScDoc(), "[SS].00"); + + // save to ODS and reload + saveAndReload("calc8"); + lcl_TestNumberFormat(*getScDoc(), "[SS].00"); +} + CPPUNIT_TEST_FIXTURE(ScExportTest4, testEmbeddedTextInDecimal) { createScDoc("xlsx/embedded-text-in-decimal.xlsx"); - lcl_TestEmbeddedTextInDecimal(*getScDoc()); + lcl_TestNumberFormat(*getScDoc(), "#,##0.000\" \"###\" \"###"); // save to ODS and reload saveAndReload("calc8"); - lcl_TestEmbeddedTextInDecimal(*getScDoc()); + lcl_TestNumberFormat(*getScDoc(), "#,##0.000\" \"###\" \"###"); } CPPUNIT_TEST_FIXTURE(ScExportTest4, testTotalsRowFunction) diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx index 06d018f3b624..8f5070c934bb 100644 --- a/svl/qa/unit/svl.cxx +++ b/svl/qa/unit/svl.cxx @@ -1728,6 +1728,23 @@ void Test::testUserDefinedNumberFormats() sExpected = "1900-01-02 23:53.605"; checkPreviewString(aFormatter, sCode, M_PI, eLang, sExpected); } + { // tdf#150028 decimals of seconds fraction withtout truncate on overflow + sCode = "[SS]"; + sExpected = "271434"; + checkPreviewString(aFormatter, sCode, M_PI, eLang, sExpected); + // One decimal. + sCode = "[SS].0"; + sExpected = "271433.6"; + checkPreviewString(aFormatter, sCode, M_PI, eLang, sExpected); + // Two decimals. + sCode = "[SS].00"; + sExpected = "271433.61"; + checkPreviewString(aFormatter, sCode, M_PI, eLang, sExpected); + // Three decimals. + sCode = "[SS].000"; + sExpected = "271433.605"; + checkPreviewString(aFormatter, sCode, M_PI, eLang, sExpected); + } { // tdf#33689 use English NfKeywords in non-English language eLang = LANGUAGE_DUTCH; sExpected = "Dutch: 1900/01/02 03:23:53"; diff --git a/svl/source/numbers/zforscan.cxx b/svl/source/numbers/zforscan.cxx index 10ff6a591b35..537c19415ff7 100644 --- a/svl/source/numbers/zforscan.cxx +++ b/svl/source/numbers/zforscan.cxx @@ -1467,6 +1467,11 @@ sal_Int32 ImpSvNumberformatScan::ScanType() } else if (pLoc->getTime100SecSep() == sStrArray[i]) bDecSep = true; + else if ( sStrArray[i][0] == ']' && i < nStringsCnt - 1 && pLoc->getTime100SecSep() == sStrArray[i+1] ) + { + bDecSep = true; + i++; + } } eNewType = SvNumFormatType::UNDEFINED; break; @@ -2592,6 +2597,7 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) bDecSep = true; nTypeArray[i] = NF_SYMBOLTYPE_DIGIT; OUString& rStr = sStrArray[i]; + nCounter++; i++; while (i < nStringsCnt && diff --git a/xmloff/source/style/xmlnumfe.cxx b/xmloff/source/style/xmlnumfe.cxx index b01c7bd8e597..59e9f7714916 100644 --- a/xmloff/source/style/xmlnumfe.cxx +++ b/xmloff/source/style/xmlnumfe.cxx @@ -1462,11 +1462,13 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt case NF_SYMBOLTYPE_PERCENT: if (pElemStr) { - if ( ( nPrevType == NF_KEY_S || nPrevType == NF_KEY_SS ) && - ( nElemType == NF_SYMBOLTYPE_TIME100SECSEP ) && + if ( ( nElemType == NF_SYMBOLTYPE_TIME100SECSEP ) && + ( nPrevType == NF_KEY_S || nPrevType == NF_KEY_SS || + ( nPos > 0 && (*rFormat.GetNumForString( nPart, nPos-1 ))[0] == ']' && + ( nFmtType == SvNumFormatType::TIME || nFmtType == SvNumFormatType::DATETIME ) ) ) && nPrecision > 0 ) { - // decimal separator after seconds is implied by + // decimal separator after seconds or [SS] is implied by // "decimal-places" attribute and must not be written // as text element //! difference between '.' and ',' is lost here