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

resolved fdo#48875 do not let ISO 8601 detection override locale's date order

If the locale's date separator was '-' the ISO 8601 detection interfered with
the locale's date order, e.g. DMY in nl_NL locale.
üst 8c1f7d99
......@@ -148,6 +148,7 @@ void ImpSvNumberInputScan::Reset()
nMayBeMonthDate = 0;
nAcceptedDatePattern = -2;
nDatePatternStart = 0;
nCanForceToIso8601 = 0;
}
......@@ -999,6 +1000,50 @@ bool ImpSvNumberInputScan::MayBeIso8601()
//---------------------------------------------------------------------------
bool ImpSvNumberInputScan::CanForceToIso8601( DateFormat eDateFormat )
{
if (nCanForceToIso8601 == 0)
{
nCanForceToIso8601 = 1;
do
{
if (!MayBeIso8601())
break;
if (nMayBeIso8601 >= 3)
{
nCanForceToIso8601 = 2; // at least 3 digits in year
break;
}
if (pFormatter->GetDateSep() != '-')
{
nCanForceToIso8601 = 2; // date separator does not interfere
break;
}
sal_Int32 n;
switch (eDateFormat)
{
case DMY: // "day" value out of range => ISO 8601 year
if ((n = sStrArray[nNums[0]].ToInt32()) < 1 || n > 31)
nCanForceToIso8601 = 2;
break;
case MDY: // "month" value out of range => ISO 8601 year
if ((n = sStrArray[nNums[0]].ToInt32()) < 1 || n > 12)
nCanForceToIso8601 = 2;
break;
case YMD: // always possible
nCanForceToIso8601 = 2;
break;
}
} while (0);
}
return nCanForceToIso8601 > 1;
}
//---------------------------------------------------------------------------
bool ImpSvNumberInputScan::MayBeMonthDate()
{
if (nMayBeMonthDate == 0)
......@@ -1596,7 +1641,7 @@ input for the following reasons:
}
}
// ISO 8601 yyyy-mm-dd forced recognition
DateFormat eDF = (MayBeIso8601() ? YMD : DateFmt);
DateFormat eDF = (CanForceToIso8601( DateFmt) ? YMD : DateFmt);
switch (eDF)
{
case MDY:
......
......@@ -71,19 +71,17 @@ public:
/// get threshold of two-digit year input
sal_uInt16 GetYear2000() const { return nYear2000; }
/** Whether input may be an ISO 8601 date format, yyyy-mm-dd...
/** Whether input can be forced to ISO 8601 format.
Checks if input has at least 3 numbers for yyyy-mm-dd and the separator
is '-', and 1<=mm<=12 and 1<=dd<=31.
Depends on locale's date separator and a specific date format order.
@see nMayBeIso8601
*/
bool MayBeIso8601();
@param eDateFormat
Evaluated only on first call during one scan process, subsequent
calls return state of nCanForceToIso8601!
/** Whether input may be a dd-month-yy format, with month name, not
number.
@see nCanForceToIso8601
*/
bool MayBeMonthDate();
bool CanForceToIso8601( DateFormat eDateFormat );
private:
SvNumberFormatter* pFormatter;
......@@ -154,6 +152,16 @@ private:
*/
sal_uInt8 nMayBeIso8601;
/** State of ISO 8601 can be forced.
0:= don't know yet
1:= no
2:= yes
@see CanForceToIso8601()
*/
sal_uInt8 nCanForceToIso8601;
/** State of dd-month-yy or yy-month-dd detection, with month name.
0:= don't know yet
......@@ -364,6 +372,22 @@ private:
*/
DateFormat GetDateOrder();
/** Whether input may be an ISO 8601 date format, yyyy-mm-dd...
Checks if input has at least 3 numbers for yyyy-mm-dd and the separator
is '-', and 1<=mm<=12 and 1<=dd<=31.
@see nMayBeIso8601
*/
bool MayBeIso8601();
/** Whether input may be a dd-month-yy format, with month name, not
number.
@see nMayBeMonthDate
*/
bool MayBeMonthDate();
#endif // _ZFORFIND_CXX
};
......
......@@ -1180,7 +1180,7 @@ bool SvNumberFormatter::IsNumberFormat(const String& sString,
{
case NUMBERFORMAT_DATE :
// Preserve ISO 8601 input.
if (pStringScanner->MayBeIso8601())
if (pStringScanner->CanForceToIso8601( DMY))
F_Index = GetFormatIndex( NF_DATE_DIN_YYYYMMDD, ActLnge );
else
F_Index = GetStandardFormat( RType, ActLnge );
......
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