diff options
author | Eike Rathke <erack@redhat.com> | 2012-04-18 19:01:09 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2012-04-18 19:01:09 +0200 |
commit | 9e1862b21684f650ebc1d8d0e5bbdd877b886945 (patch) | |
tree | 0d9f4a111be9a94a2c372e9f7d40a7060c9da563 | |
parent | 8c1f7d99f27fe6ec6aadd58d4350d8406ccb7e14 (diff) |
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.
-rw-r--r-- | svl/source/numbers/zforfind.cxx | 47 | ||||
-rw-r--r-- | svl/source/numbers/zforfind.hxx | 42 | ||||
-rw-r--r-- | svl/source/numbers/zforlist.cxx | 2 |
3 files changed, 80 insertions, 11 deletions
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx index 3c5d835e5658..cce08f984faa 100644 --- a/svl/source/numbers/zforfind.cxx +++ b/svl/source/numbers/zforfind.cxx @@ -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: diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx index e808c30e77d7..c57c90aa47cf 100644 --- a/svl/source/numbers/zforfind.hxx +++ b/svl/source/numbers/zforfind.hxx @@ -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 }; diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index d897274e002d..83a123296a33 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.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 ); |