sc/qa/unit/subsequent_export-test.cxx |    5 ++++-
 svl/source/numbers/zformat.cxx        |   30 +++++++++++++++++++++++++++---
 2 files changed, 31 insertions(+), 4 deletions(-)

New commits:
commit c98891a4ba67a73d7a683ffb24845512705a4bbf
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Mon Mar 15 15:57:18 2021 +0100
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Mon Mar 15 20:25:47 2021 +0100

    xls load: suppress secondary [~gengou] calendar modifier in format code
    
    ja-JP Gengou calendar is an implicit secondary calendar switched
    to and from by format codes.
    
    Change-Id: Iea268310ac5e917f2168fec0166754424baa925d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112511
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/sc/qa/unit/subsequent_export-test.cxx 
b/sc/qa/unit/subsequent_export-test.cxx
index 0d14b1046793..b0f390206129 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -4725,7 +4725,10 @@ void ScExportTest::testExtendedLCIDXLSX()
     SvNumberFormatter* pNumFormatter = rDoc.GetFormatTable();
     sal_uInt32 nNumberFormat;
     const OUString aLang[5] = { "[$-41E]", "[$-411]", "[$-40D]", "[$-401]", 
"[$-500]" };
-    const OUString aCalendar[5] = { "[~buddhist]DD-MM-YYYY", 
"[~gengou]DD-MM-EE", "[~jewish]DD-MM-YYYY", "[~hijri]DD-MM-YYYY", 
"[~dangi]YYYY/MM/DD" };
+    const OUString aCalendar[5] = { "[~buddhist]DD-MM-YYYY", "DD-MM-EE", 
"[~jewish]DD-MM-YYYY", "[~hijri]DD-MM-YYYY", "[~dangi]YYYY/MM/DD" };
+    // Note: ja-JP Gengou calendar is an implicit secondary (non-gregorian)
+    // calendar, the explicit [~gengou] calendar modifier does not need to be
+    // present, the E and EE keywords are used instead of YY and YYYY.
     for ( sal_Int16 nCol = 1; nCol <= 2; nCol++ )
     {
         for ( sal_Int16 nRow = 1; nRow <= 4; nRow++ )
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 8787f0977984..f74b178a0419 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -442,8 +442,10 @@ OUString SvNumberformat::ImpObtainCalendarAndNumerals( 
OUStringBuffer& rString,
     switch ( aTmpLocale.mnCalendarType & 0x7F )
     {
         case 0x03 : // Gengou calendar
-            sCalendar = "[~gengou]";
-            // Only Japanese language support Gengou calendar
+            // Only Japanese language support Gengou calendar.
+            // It is an implicit "other" calendar where E, EE, R and RR
+            // automatically switch to and YY and YYYY switch to Gregorian. Do
+            // not add the "[~gengou]" modifier.
             if ( nLocaleLang != LANGUAGE_JAPANESE )
             {
                 nLang = maLocale.meLanguage = LANGUAGE_JAPANESE;
@@ -5252,6 +5254,7 @@ OUString SvNumberformat::GetMappedFormatstring( const 
NfKeywordTable& rKeywords,
         sal_Int32 nPosHaveLCID = -1;
         sal_Int32 nPosInsertLCID = aStr.getLength();
         sal_uInt32 nCalendarID = 0x0000000; // Excel ID of calendar used in 
sub-format see tdf#36038
+        constexpr sal_uInt32 kCalGengou = 0x0030000;
         if ( nCnt )
         {
             auto& rTypeArray = NumFor[n].Info().nTypeArray;
@@ -5265,6 +5268,27 @@ OUString SvNumberformat::GetMappedFormatstring( const 
NfKeywordTable& rKeywords,
                     {
                         aStr.append( rLocWrp.getLongDateDayOfWeekSep() );
                     }
+                    switch (rTypeArray[j])
+                    {
+                        case NF_KEY_EC:
+                        case NF_KEY_EEC:
+                        case NF_KEY_R:
+                        case NF_KEY_RR:
+                            // Implicit secondary (non-gregorian) calendar.
+                            // Currently only for ja-JP.
+                            /* TODO: same for all locales in
+                             * LocaleDataWrapper::doesSecondaryCalendarUseEC() 
?
+                             * Should split the locales off that then. */
+                            if (!nCalendarID)
+                            {
+                                const LanguageType nLang = 
MsLangId::getRealLanguage( nOriginalLang);
+                                if (nLang == LANGUAGE_JAPANESE)
+                                    nCalendarID = kCalGengou;
+                            }
+                        break;
+                        default:
+                            ;   // nothing
+                    }
                 }
                 else
                 {
@@ -5313,7 +5337,7 @@ OUString SvNumberformat::GetMappedFormatstring( const 
NfKeywordTable& rKeywords,
                             break;
                         if ( rStrArray[j+1] == "gengou" )
                         {
-                            nCalendarID = 0x0030000;
+                            nCalendarID = kCalGengou;
                         }
                         else if ( rStrArray[j+1] == "hijri" )
                         {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to