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
This commit is contained in:
Eike Rathke
2013-02-28 18:34:41 +01:00
parent c66b914a7f
commit be16dba682
2 changed files with 40 additions and 21 deletions

View File

@@ -30,10 +30,13 @@
namespace com { namespace sun { namespace star { namespace i18n { namespace com { namespace sun { namespace star { namespace i18n {
const sal_uInt8 kDisplayEraForcedLongYear = 0x01;
struct Era { struct Era {
sal_Int32 year; sal_Int32 year;
sal_Int32 month; sal_Int32 month;
sal_Int32 day; sal_Int32 day;
sal_uInt8 flags;
}; };
const sal_Int16 FIELD_INDEX_COUNT = CalendarFieldIndex::FIELD_COUNT2; const sal_Int16 FIELD_INDEX_COUNT = CalendarFieldIndex::FIELD_COUNT2;
@@ -101,6 +104,8 @@ protected:
virtual void mapFromGregorian() throw(com::sun::star::uno::RuntimeException); virtual void mapFromGregorian() throw(com::sun::star::uno::RuntimeException);
void getValue() 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: private:
Calendar2 aCalendar; Calendar2 aCalendar;

View File

@@ -200,11 +200,11 @@ Calendar_hanja::loadCalendar( const OUString& /*uniqueID*/, const com::sun::star
} }
static Era gengou_eraArray[] = { static Era gengou_eraArray[] = {
{1868, 1, 1}, {1868, 1, 1, 0},
{1912, 7, 30}, {1912, 7, 30, 0},
{1926, 12, 25}, {1926, 12, 25, 0},
{1989, 1, 8}, {1989, 1, 8, 0},
{0, 0, 0} {0, 0, 0, 0}
}; };
Calendar_gengou::Calendar_gengou() : Calendar_gregorian(gengou_eraArray) Calendar_gengou::Calendar_gengou() : Calendar_gregorian(gengou_eraArray)
{ {
@@ -212,8 +212,8 @@ Calendar_gengou::Calendar_gengou() : Calendar_gregorian(gengou_eraArray)
} }
static Era ROC_eraArray[] = { static Era ROC_eraArray[] = {
{1912, 1, 1}, {1912, 1, 1, kDisplayEraForcedLongYear}, // #i116701#
{0, 0, 0} {0, 0, 0, 0}
}; };
Calendar_ROC::Calendar_ROC() : Calendar_gregorian(ROC_eraArray) Calendar_ROC::Calendar_ROC() : Calendar_gregorian(ROC_eraArray)
{ {
@@ -221,8 +221,8 @@ Calendar_ROC::Calendar_ROC() : Calendar_gregorian(ROC_eraArray)
} }
static Era buddhist_eraArray[] = { static Era buddhist_eraArray[] = {
{-542, 1, 1}, {-542, 1, 1, 0},
{0, 0, 0} {0, 0, 0, 0}
}; };
Calendar_buddhist::Calendar_buddhist() : Calendar_gregorian(buddhist_eraArray) Calendar_buddhist::Calendar_buddhist() : Calendar_gregorian(buddhist_eraArray)
{ {
@@ -1001,6 +1001,13 @@ Calendar_gregorian::getDisplayName( sal_Int16 displayIndex, sal_Int16 idx, sal_I
OUString SAL_CALL OUString SAL_CALL
Calendar_gregorian::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) Calendar_gregorian::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode )
throw (RuntimeException) 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) )); sal_Int16 value = getValue(sal::static_int_cast<sal_Int16>( DisplayCode2FieldIndex(nCalendarDisplayCode) ));
OUString aOUStr; OUString aOUStr;
@@ -1045,10 +1052,17 @@ Calendar_gregorian::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16
break; break;
case CalendarDisplayCode::SHORT_YEAR: case CalendarDisplayCode::SHORT_YEAR:
// Take last 2 digits, or only one if value<10, for example, // Take last 2 digits, or only one if value<10, for example,
// in case of the Gengou calendar. // in case of the Gengou calendar. For combined era+year always
// #i116701# For values in non-Gregorian era years use all // the full year is displayed, without leading 0.
// digits. // Workaround for non-combined calls in certain calendars is
if (value < 100 || eraArray) // 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 sprintf(aStr, "%d", value); // #100211# - checked
else else
sprintf(aStr, "%02d", value % 100); // #100211# - checked sprintf(aStr, "%02d", value % 100); // #100211# - checked
@@ -1087,12 +1101,12 @@ Calendar_gregorian::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16
return getDisplayName(CalendarDisplayIndex::ERA, value, 1); return getDisplayName(CalendarDisplayIndex::ERA, value, 1);
case CalendarDisplayCode::SHORT_YEAR_AND_ERA: case CalendarDisplayCode::SHORT_YEAR_AND_ERA:
return getDisplayString( CalendarDisplayCode::SHORT_ERA, nNativeNumberMode ) + return getDisplayStringImpl( CalendarDisplayCode::SHORT_ERA, nNativeNumberMode, true ) +
getDisplayString( CalendarDisplayCode::SHORT_YEAR, nNativeNumberMode ); getDisplayStringImpl( CalendarDisplayCode::SHORT_YEAR, nNativeNumberMode, true );
case CalendarDisplayCode::LONG_YEAR_AND_ERA: case CalendarDisplayCode::LONG_YEAR_AND_ERA:
return getDisplayString( CalendarDisplayCode::LONG_ERA, nNativeNumberMode ) + return getDisplayStringImpl( CalendarDisplayCode::LONG_ERA, nNativeNumberMode, true ) +
getDisplayString( CalendarDisplayCode::LONG_YEAR, nNativeNumberMode ); getDisplayStringImpl( CalendarDisplayCode::LONG_YEAR, nNativeNumberMode, true );
default: default:
throw ERROR; throw ERROR;
@@ -1126,11 +1140,11 @@ Calendar_buddhist::getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 n
nCalendarDisplayCode == CalendarDisplayCode::SHORT_YEAR_AND_ERA) && nCalendarDisplayCode == CalendarDisplayCode::SHORT_YEAR_AND_ERA) &&
getValue(CalendarFieldIndex::ERA) == 0) { getValue(CalendarFieldIndex::ERA) == 0) {
if (nCalendarDisplayCode == CalendarDisplayCode::LONG_YEAR_AND_ERA) if (nCalendarDisplayCode == CalendarDisplayCode::LONG_YEAR_AND_ERA)
return getDisplayString( CalendarDisplayCode::SHORT_YEAR, nNativeNumberMode ) + return getDisplayStringImpl( CalendarDisplayCode::SHORT_YEAR, nNativeNumberMode, true ) +
getDisplayString( CalendarDisplayCode::SHORT_ERA, nNativeNumberMode ); getDisplayStringImpl( CalendarDisplayCode::SHORT_ERA, nNativeNumberMode, true );
else else
return getDisplayString( CalendarDisplayCode::LONG_YEAR, nNativeNumberMode ) + return getDisplayStringImpl( CalendarDisplayCode::LONG_YEAR, nNativeNumberMode, true ) +
getDisplayString( CalendarDisplayCode::LONG_ERA, nNativeNumberMode ); getDisplayStringImpl( CalendarDisplayCode::LONG_ERA, nNativeNumberMode, true );
} }
return Calendar_gregorian::getDisplayString(nCalendarDisplayCode, nNativeNumberMode); return Calendar_gregorian::getDisplayString(nCalendarDisplayCode, nNativeNumberMode);
} }