Kaydet (Commit) b0aaaeb7 authored tarafından Eike Rathke's avatar Eike Rathke

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

üst f31656f1
......@@ -596,7 +596,8 @@ public:
bool IsSpecialStandardFormat( sal_uInt32 nFIndex, LanguageType eLnge );
/** 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
Date* GetNullDate();
......
......@@ -456,6 +456,15 @@ public:
return false;
}
#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:
ImpSvNumFor NumFor[4]; // Array for the 4 subformats
String sFormatstring; // The format code string
......@@ -476,6 +485,11 @@ private:
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
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;
#ifdef THE_FUTURE
SVL_DLLPRIVATE bool ImpSwitchToSpecifiedCalendar( String& rOrgCalendar,
double& fOrgDateTime, const ImpSvNumFor& rNumFor ) const;
#endif
/// Whether it's a (YY)YY-M(M)-D(D) format.
SVL_DLLPRIVATE bool ImpIsIso8601( const ImpSvNumFor& rNumFor );
#ifdef _ZFORMAT_CXX // ----- private implementation methods -----
......
......@@ -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;
switch ( eType )
......@@ -1456,7 +1457,8 @@ sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex,
// Preserve ISO 8601 format.
if ( nFIndex == GetFormatIndex( NF_DATE_DIN_YYYYMMDD, 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);
else
nKey = GetFormatIndex( NF_DATE_SYS_DDMMYYYY, eLang );
......@@ -1517,7 +1519,7 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber,
ChangeStandardPrec(INPUTSTRING_PRECISION);
bPrecChanged = true;
}
sal_uInt32 nKey = GetEditFormat( fOutNumber, nFIndex, eType, eLang);
sal_uInt32 nKey = GetEditFormat( fOutNumber, nFIndex, eType, eLang, pFormat);
if ( nKey != nFIndex )
pFormat = (SvNumberformat*) aFTable.Get( nKey );
if (pFormat)
......
......@@ -3195,6 +3195,74 @@ void SvNumberformat::ImpAppendEraG( String& OutString,
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,
sal_uInt16 nIx,
String& OutString)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment