recognize arbitrary y-m-d format for editing as ISO 8601 yyyy-mm-dd

This commit is contained in:
Eike Rathke
2011-12-22 18:59:41 +01:00
parent f31656f18a
commit b0aaaeb7bd
4 changed files with 91 additions and 8 deletions

View File

@@ -596,7 +596,8 @@ public:
bool IsSpecialStandardFormat( sal_uInt32 nFIndex, LanguageType eLnge ); bool IsSpecialStandardFormat( sal_uInt32 nFIndex, LanguageType eLnge );
/** Return the corresponding edit format of a format. */ /** Return the corresponding edit format of a format. */
sal_uInt32 GetEditFormat( double fNumber, sal_uInt32 nFIndex, short eType, LanguageType eLnge ); sal_uInt32 GetEditFormat( double fNumber, sal_uInt32 nFIndex, short eType,
LanguageType eLnge, SvNumberformat* pFormat );
/// Return the reference date /// Return the reference date
Date* GetNullDate(); Date* GetNullDate();

View File

@@ -456,6 +456,15 @@ public:
return false; return false;
} }
#endif #endif
/// Whether it's a (YY)YY-M(M)-D(D) format.
bool IsIso8601( sal_uInt16 nNumFor )
{
if ( nNumFor < 4 )
return ImpIsIso8601( NumFor[nNumFor]);
return false;
}
private: private:
ImpSvNumFor NumFor[4]; // Array for the 4 subformats ImpSvNumFor NumFor[4]; // Array for the 4 subformats
String sFormatstring; // The format code string String sFormatstring; // The format code string
@@ -476,6 +485,11 @@ private:
SVL_DLLPRIVATE bool ImpIsOtherCalendar( const ImpSvNumFor& rNumFor ) const; SVL_DLLPRIVATE bool ImpIsOtherCalendar( const ImpSvNumFor& rNumFor ) const;
#ifdef THE_FUTURE
SVL_DLLPRIVATE bool ImpSwitchToSpecifiedCalendar( String& rOrgCalendar,
double& fOrgDateTime, const ImpSvNumFor& rNumFor ) const;
#endif
/** Whether to use possessive genitive case month name, or partitive case /** Whether to use possessive genitive case month name, or partitive case
month name, instead of nominative name (noun). month name, instead of nominative name (noun).
@@ -496,10 +510,8 @@ private:
*/ */
SVL_DLLPRIVATE sal_Int32 ImpUseMonthCase( int & io_nState, const ImpSvNumFor& rNumFor, NfKeywordIndex eCodeType ) const; SVL_DLLPRIVATE sal_Int32 ImpUseMonthCase( int & io_nState, const ImpSvNumFor& rNumFor, NfKeywordIndex eCodeType ) const;
#ifdef THE_FUTURE /// Whether it's a (YY)YY-M(M)-D(D) format.
SVL_DLLPRIVATE bool ImpSwitchToSpecifiedCalendar( String& rOrgCalendar, SVL_DLLPRIVATE bool ImpIsIso8601( const ImpSvNumFor& rNumFor );
double& fOrgDateTime, const ImpSvNumFor& rNumFor ) const;
#endif
#ifdef _ZFORMAT_CXX // ----- private implementation methods ----- #ifdef _ZFORMAT_CXX // ----- private implementation methods -----

View File

@@ -1437,7 +1437,8 @@ sal_uInt32 SvNumberFormatter::GetStandardFormat( double fNumber, sal_uInt32 nFIn
} }
} }
sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex, short eType, LanguageType eLang ) sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex,
short eType, LanguageType eLang, SvNumberformat* pFormat )
{ {
sal_uInt32 nKey = nFIndex; sal_uInt32 nKey = nFIndex;
switch ( eType ) switch ( eType )
@@ -1456,7 +1457,8 @@ sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex,
// Preserve ISO 8601 format. // Preserve ISO 8601 format.
if ( nFIndex == GetFormatIndex( NF_DATE_DIN_YYYYMMDD, eLang) || if ( nFIndex == GetFormatIndex( NF_DATE_DIN_YYYYMMDD, eLang) ||
nFIndex == GetFormatIndex( NF_DATE_DIN_YYMMDD, eLang) || nFIndex == GetFormatIndex( NF_DATE_DIN_YYMMDD, eLang) ||
nFIndex == GetFormatIndex( NF_DATE_DIN_MMDD, eLang)) nFIndex == GetFormatIndex( NF_DATE_DIN_MMDD, eLang) ||
(pFormat && pFormat->IsIso8601( 0 )))
nKey = GetFormatIndex( NF_DATE_DIN_YYYYMMDD, eLang); nKey = GetFormatIndex( NF_DATE_DIN_YYYYMMDD, eLang);
else else
nKey = GetFormatIndex( NF_DATE_SYS_DDMMYYYY, eLang ); nKey = GetFormatIndex( NF_DATE_SYS_DDMMYYYY, eLang );
@@ -1517,7 +1519,7 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber,
ChangeStandardPrec(INPUTSTRING_PRECISION); ChangeStandardPrec(INPUTSTRING_PRECISION);
bPrecChanged = true; bPrecChanged = true;
} }
sal_uInt32 nKey = GetEditFormat( fOutNumber, nFIndex, eType, eLang); sal_uInt32 nKey = GetEditFormat( fOutNumber, nFIndex, eType, eLang, pFormat);
if ( nKey != nFIndex ) if ( nKey != nFIndex )
pFormat = (SvNumberformat*) aFTable.Get( nKey ); pFormat = (SvNumberformat*) aFTable.Get( nKey );
if (pFormat) if (pFormat)

View File

@@ -3195,6 +3195,74 @@ void SvNumberformat::ImpAppendEraG( String& OutString,
OutString += rCal.getDisplayString( CalendarDisplayCode::SHORT_ERA, nNatNum ); OutString += rCal.getDisplayString( CalendarDisplayCode::SHORT_ERA, nNatNum );
} }
bool SvNumberformat::ImpIsIso8601( const ImpSvNumFor& rNumFor )
{
bool bIsIso = false;
if ((eType & NUMBERFORMAT_DATE) == NUMBERFORMAT_DATE)
{
enum State
{
eNone,
eAtYear,
eAtSep1,
eAtMonth,
eAtSep2,
eNotIso
};
State eState = eNone;
short const * const pType = rNumFor.Info().nTypeArray;
sal_uInt16 nAnz = rNumFor.GetCount();
for (sal_uInt16 i=0; i < nAnz && !bIsIso && eState != eNotIso; ++i)
{
switch ( pType[i] )
{
case NF_KEY_YY: // two digits not strictly ISO 8601
case NF_KEY_YYYY:
if (eState != eNone)
eState = eNotIso;
else
eState = eAtYear;
break;
case NF_KEY_M: // single digit not strictly ISO 8601
case NF_KEY_MM:
if (eState != eAtSep1)
eState = eNotIso;
else
eState = eAtMonth;
break;
case NF_KEY_D: // single digit not strictly ISO 8601
case NF_KEY_DD:
if (eState != eAtSep2)
eState = eNotIso;
else
bIsIso = true;
break;
case NF_SYMBOLTYPE_STRING:
case NF_SYMBOLTYPE_DATESEP:
if (rNumFor.Info().sStrArray[i] == '-')
{
if (eState == eAtYear)
eState = eAtSep1;
else if (eState == eAtMonth)
eState = eAtSep2;
else
eState = eNotIso;
}
else
eState = eNotIso;
break;
default:
eState = eNotIso;
}
}
}
else
{
OSL_FAIL( "SvNumberformat::ImpIsIso8601: no date" );
}
return bIsIso;
}
bool SvNumberformat::ImpGetDateOutput(double fNumber, bool SvNumberformat::ImpGetDateOutput(double fNumber,
sal_uInt16 nIx, sal_uInt16 nIx,
String& OutString) String& OutString)