From e12c9b41012e44275761b35795b83ec4bc838d42 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Tue, 13 Sep 2016 19:33:11 +0200 Subject: do not add calendar modifier to format code when importing as E or EE keyword ... with implicit calendar switch. Change-Id: Ie4d848e261fe86bbe504954b2e0c7cf24bc181bc --- xmloff/source/style/xmlnumfi.cxx | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'xmloff/source/style') diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx index 164ce769912a..257d945efef1 100644 --- a/xmloff/source/style/xmlnumfi.cxx +++ b/xmloff/source/style/xmlnumfi.cxx @@ -1201,20 +1201,33 @@ void SvXMLNumFmtElementContext::EndElement() : ( bEffLong ? NF_KEY_MM : NF_KEY_M ) ) ); break; case XML_TOK_STYLE_YEAR: - rParent.UpdateCalendar( sCalendar ); //! I18N doesn't provide SYSTEM or extended date information yet - // Y after G (era) is replaced by E, also if we're switching to the - // other second known calendar for a locale. - if ( rParent.HasEra() || rParent.GetLocaleData().doesSecondaryCalendarUseEC( sCalendar)) { - rParent.AddNfKeyword( - sal::static_int_cast< sal_uInt16 >( - bEffLong ? NF_KEY_EEC : NF_KEY_EC ) ); + // Y after G (era) is replaced by E, also if we're switching to the + // other second known calendar for a locale. + bool bImplicitEC = (!sCalendar.isEmpty() && + rParent.GetLocaleData().doesSecondaryCalendarUseEC( sCalendar)); + if (rParent.HasEra() || bImplicitEC) + { + // If E or EE is the first format keyword, passing + // bImplicitEC=true suppresses the superfluous calendar + // modifier for this format. This does not help for + // something like [~cal]DD/MM/EE but so far only YMD order + // is used with such calendars. Live with the modifier if + // other keywords precede this. + rParent.UpdateCalendar( sCalendar, bImplicitEC); + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bEffLong ? NF_KEY_EEC : NF_KEY_EC ) ); + } + else + { + rParent.UpdateCalendar( sCalendar ); + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bEffLong ? NF_KEY_YYYY : NF_KEY_YY ) ); + } } - else - rParent.AddNfKeyword( - sal::static_int_cast< sal_uInt16 >( - bEffLong ? NF_KEY_YYYY : NF_KEY_YY ) ); break; case XML_TOK_STYLE_ERA: rParent.UpdateCalendar( sCalendar ); @@ -2257,12 +2270,12 @@ void SvXMLNumFormatContext::AddColor( sal_uInt32 const nColor ) } } -void SvXMLNumFormatContext::UpdateCalendar( const OUString& rNewCalendar ) +void SvXMLNumFormatContext::UpdateCalendar( const OUString& rNewCalendar, bool bImplicitSecondaryCalendarEC ) { if ( rNewCalendar != sCalendar ) { sCalendar = rNewCalendar; - if ( !sCalendar.isEmpty() ) + if ( !sCalendar.isEmpty() && !bImplicitSecondaryCalendarEC ) { aFormatCode.append( "[~" ); // intro for calendar code aFormatCode.append( sCalendar ); -- cgit