[PATCH libreoffice-3-6] resolved fdo#60915 force long year only for ROC calendar

Eike Rathke (via Code Review) gerrit at gerrit.libreoffice.org
Thu Feb 28 16:17:28 PST 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2477

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/77/2477/1

resolved fdo#60915 force long year only for ROC calendar

Long year was forced unconditionally for all non-Gregorian calendars, do
this only for ROC calendar.

Change-Id: I39d6eb269b3d38046d32dcf0f66edd5617581b9d
(cherry picked from commit be16dba682b8ab1c244f8d24f1bab3a539096962)
---
M i18npool/inc/calendar_gregorian.hxx
M i18npool/source/calendar/calendar_gregorian.cxx
2 files changed, 40 insertions(+), 21 deletions(-)



diff --git a/i18npool/inc/calendar_gregorian.hxx b/i18npool/inc/calendar_gregorian.hxx
index 03e4e81..9744be2 100644
--- a/i18npool/inc/calendar_gregorian.hxx
+++ b/i18npool/inc/calendar_gregorian.hxx
@@ -39,10 +39,13 @@
 
 namespace com { namespace sun { namespace star { namespace i18n {
 
+const sal_uInt8 kDisplayEraForcedLongYear = 0x01;
+
 struct Era {
     sal_Int32 year;
     sal_Int32 month;
     sal_Int32 day;
+    sal_uInt8 flags;
 };
 
 const sal_Int16 FIELD_INDEX_COUNT = CalendarFieldIndex::FIELD_COUNT2;
@@ -110,6 +113,8 @@
     virtual void mapFromGregorian() throw(com::sun::star::uno::RuntimeException);
     void getValue() throw(com::sun::star::uno::RuntimeException);
 
+    rtl::OUString getDisplayStringImpl( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode, bool bEraMode ) throw (com::sun::star::uno::RuntimeException);
+
 private:
     Calendar2 aCalendar;
 
diff --git a/i18npool/source/calendar/calendar_gregorian.cxx b/i18npool/source/calendar/calendar_gregorian.cxx
index e32d391..e76c431 100644
--- a/i18npool/source/calendar/calendar_gregorian.cxx
+++ b/i18npool/source/calendar/calendar_gregorian.cxx
@@ -209,11 +209,11 @@
 }
 
 static Era gengou_eraArray[] = {
-    {1868,  1,  1},
-    {1912,  7, 30},
-    {1926, 12, 25},
-    {1989,  1,  8},
-    {0, 0,  0}
+    {1868,  1,  1, 0},
+    {1912,  7, 30, 0},
+    {1926, 12, 25, 0},
+    {1989,  1,  8, 0},
+    {0, 0, 0, 0}
 };
 Calendar_gengou::Calendar_gengou() : Calendar_gregorian(gengou_eraArray)
 {
@@ -221,8 +221,8 @@
 }
 
 static Era ROC_eraArray[] = {
-    {1912, 1, 1},
-    {0, 0,  0}
+    {1912, 1, 1, kDisplayEraForcedLongYear},    // #i116701#
+    {0, 0, 0, 0}
 };
 Calendar_ROC::Calendar_ROC() : Calendar_gregorian(ROC_eraArray)
 {
@@ -230,8 +230,8 @@
 }
 
 static Era buddhist_eraArray[] = {
-    {-542, 1, 1},
-    {0, 0,  0}
+    {-542, 1, 1, 0},
+    {0, 0, 0, 0}
 };
 Calendar_buddhist::Calendar_buddhist() : Calendar_gregorian(buddhist_eraArray)
 {
@@ -1011,6 +1011,13 @@
 Calendar_gregorian::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode )
         throw (RuntimeException)
 {
+    return getDisplayStringImpl( nCalendarDisplayCode, nNativeNumberMode, false);
+}
+
+OUString
+Calendar_gregorian::getDisplayStringImpl( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode, bool bEraMode )
+        throw (RuntimeException)
+{
     sal_Int16 value = getValue(sal::static_int_cast<sal_Int16>( DisplayCode2FieldIndex(nCalendarDisplayCode) ));
     OUString aOUStr;
 
@@ -1054,10 +1061,17 @@
                 break;
             case CalendarDisplayCode::SHORT_YEAR:
                 // Take last 2 digits, or only one if value<10, for example,
-                // in case of the Gengou calendar.
-                // #i116701# For values in non-Gregorian era years use all
-                // digits.
-                if (value < 100 || eraArray)
+                // in case of the Gengou calendar. For combined era+year always
+                // the full year is displayed, without leading 0.
+                // Workaround for non-combined calls in certain calendars is
+                // the kDisplayEraForcedLongYear flag, but this also could get
+                // called for YY not only E format codes, no differentiation
+                // possible here; the good news is that usually the Gregorian
+                // calendar is the default and hence YY calls for Gregorian and
+                // E for the other calendar and currently (2013-02-28) ROC is
+                // the only calendar using this.
+                // See i#116701 and fdo#60915
+                if (value < 100 || bEraMode || (eraArray && (eraArray[0].flags & kDisplayEraForcedLongYear)))
                     sprintf(aStr, "%d", value); // #100211# - checked
                 else
                     sprintf(aStr, "%02d", value % 100); // #100211# - checked
@@ -1096,12 +1110,12 @@
                 return getDisplayName(CalendarDisplayIndex::ERA, value, 1);
 
             case CalendarDisplayCode::SHORT_YEAR_AND_ERA:
-                return  getDisplayString( CalendarDisplayCode::SHORT_ERA, nNativeNumberMode ) +
-                    getDisplayString( CalendarDisplayCode::SHORT_YEAR, nNativeNumberMode );
+                return  getDisplayStringImpl( CalendarDisplayCode::SHORT_ERA, nNativeNumberMode, true ) +
+                    getDisplayStringImpl( CalendarDisplayCode::SHORT_YEAR, nNativeNumberMode, true );
 
             case CalendarDisplayCode::LONG_YEAR_AND_ERA:
-                return  getDisplayString( CalendarDisplayCode::LONG_ERA, nNativeNumberMode ) +
-                    getDisplayString( CalendarDisplayCode::LONG_YEAR, nNativeNumberMode );
+                return  getDisplayStringImpl( CalendarDisplayCode::LONG_ERA, nNativeNumberMode, true ) +
+                    getDisplayStringImpl( CalendarDisplayCode::LONG_YEAR, nNativeNumberMode, true );
 
             default:
                 throw ERROR;
@@ -1135,11 +1149,11 @@
                 nCalendarDisplayCode == CalendarDisplayCode::SHORT_YEAR_AND_ERA) &&
             getValue(CalendarFieldIndex::ERA) == 0) {
         if (nCalendarDisplayCode == CalendarDisplayCode::LONG_YEAR_AND_ERA)
-            return  getDisplayString( CalendarDisplayCode::SHORT_YEAR, nNativeNumberMode ) +
-                getDisplayString( CalendarDisplayCode::SHORT_ERA, nNativeNumberMode );
+            return  getDisplayStringImpl( CalendarDisplayCode::SHORT_YEAR, nNativeNumberMode, true ) +
+                getDisplayStringImpl( CalendarDisplayCode::SHORT_ERA, nNativeNumberMode, true );
         else
-            return  getDisplayString( CalendarDisplayCode::LONG_YEAR, nNativeNumberMode ) +
-                getDisplayString( CalendarDisplayCode::LONG_ERA, nNativeNumberMode );
+            return  getDisplayStringImpl( CalendarDisplayCode::LONG_YEAR, nNativeNumberMode, true ) +
+                getDisplayStringImpl( CalendarDisplayCode::LONG_ERA, nNativeNumberMode, true );
     }
     return Calendar_gregorian::getDisplayString(nCalendarDisplayCode, nNativeNumberMode);
 }

-- 
To view, visit https://gerrit.libreoffice.org/2477
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I39d6eb269b3d38046d32dcf0f66edd5617581b9d
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-3-6
Gerrit-Owner: Eike Rathke <erack at redhat.com>



More information about the LibreOffice mailing list