summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2012-08-29 20:49:01 +0200
committerEike Rathke <erack@redhat.com>2012-08-29 21:17:46 +0200
commitcda156257003df673fa853a0a5ffcd1cb4848d43 (patch)
tree5fcd7aa0c1c8e5de2da387e069423530500b15b4 /svl
parent332451bea5ebe08136de2d51e0e29cac88f89e8c (diff)
resolved fdo#52240 fdo#52137 fdo#52288 user editable date patterns
Implemented user editable date acceptance patterns. The introduction of strict date parsing using locale dependent date acceptance patterns in 3.6.0 wasn't always welcomed. Besides that not every locale had patterns for incomplete (only day and month) date input, users also complained about not being able to key in dates on numeric keypads if the locale's date separator wasn't '/' or '-' This commit implements a "Date acceptance patterns" edit field under Tools->Options->LanguageSettings->Languages that follows the selected locale and enables the user to add patterns. Example de-DE locale: * default patterns: D.M.Y;D.M. * to enable additional input on numeric keypad: D.M.Y;D.M.;D-M-Y;D-M * if 3-4 shall not result in a date, D-M- could be used instead of D-M * note that to enter an ISO 8601 Y-M-D date with a D-M-Y pattern active one needs to enter a year >31 or with at least 3 digits, e.g. 011 Change-Id: I9e20fcb168578b02d0f0248a0e209942e0f27113
Diffstat (limited to 'svl')
-rw-r--r--svl/inc/svl/zforlist.hxx4
-rw-r--r--svl/source/numbers/zforfind.cxx55
-rw-r--r--svl/source/numbers/zforfind.hxx2
-rw-r--r--svl/source/numbers/zforlist.cxx37
4 files changed, 77 insertions, 21 deletions
diff --git a/svl/inc/svl/zforlist.hxx b/svl/inc/svl/zforlist.hxx
index 1cace08d22bf..5b7ab3861182 100644
--- a/svl/inc/svl/zforlist.hxx
+++ b/svl/inc/svl/zforlist.hxx
@@ -943,6 +943,10 @@ public:
// called by SvNumberFormatterRegistry_Impl::Notify if the default system currency changes
void ResetDefaultSystemCurrency();
+ // Called by SvNumberFormatterRegistry_Impl::Notify if the system locale's
+ // date acceptence patterns change.
+ void InvalidateDateAcceptancePatterns();
+
// Replace the SYSTEM language/country format codes. Called upon change of
// the user configurable locale.
// Old compatibility codes are replaced, user defined are converted, and
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index 6d0cbdc93551..fb5bbe3ad821 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -1012,12 +1012,6 @@ bool ImpSvNumberInputScan::CanForceToIso8601( DateFormat eDateFormat )
break;
}
- if (!comphelper::string::equals(pFormatter->GetDateSep(), '-'))
- {
- nCanForceToIso8601 = 2; // date separator does not interfere
- break;
- }
-
sal_Int32 n;
switch (eDateFormat)
{
@@ -1292,6 +1286,18 @@ DateFormat ImpSvNumberInputScan::GetDateOrder()
return DMY;
}
break;
+ default:
+ case 0:
+ switch ((nOrder & 0xff))
+ {
+ case 'Y':
+ return YMD;
+ case 'M':
+ return MDY;
+ case 'D':
+ return DMY;
+ }
+ break;
}
}
SAL_WARN( "nf.date", "ImpSvNumberInputScan::GetDateOrder: undefined, falling back to locale's default");
@@ -1432,8 +1438,30 @@ input for the following reasons:
nCounter = 1;
switch (nMonthPos) // where is the month
{
- case 0: // not found => only day entered
- pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) );
+ case 0: // not found
+ {
+ // If input matched a date pattern, use the pattern
+ // to determine if it is a day, month or year. The
+ // pattern should have only one single value then,
+ // 'D-', 'M-' or 'Y-'. If input did not match a
+ // pattern assume the usual day of current month.
+ sal_uInt32 nDateOrder = (bFormatTurn ?
+ pFormat->GetExactDateOrder() :
+ GetDatePatternOrder());
+ switch (nDateOrder)
+ {
+ case 'Y':
+ pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(0) );
+ break;
+ case 'M':
+ pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(0) );
+ break;
+ case 'D':
+ default:
+ pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) );
+ break;
+ }
+ }
break;
case 1: // month at the beginning (Jan 01)
pCal->setValue( CalendarFieldIndex::MONTH, Abs(nMonth)-1 );
@@ -2223,6 +2251,7 @@ bool ImpSvNumberInputScan::ScanEndString( const String& rString,
}
}
+ bool bSignDetectedHere = false;
if ( nSign == 0 // conflict - not signed
&& eScannedType != NUMBERFORMAT_DATE) // and not date
//!? catch time too?
@@ -2230,6 +2259,8 @@ bool ImpSvNumberInputScan::ScanEndString( const String& rString,
nSign = GetSign(rString, nPos); // 1- DM
if (nNegCheck) // '(' as sign
return MatchedReturn();
+ if (nSign)
+ bSignDetectedHere = true;
}
SkipBlanks(rString, nPos);
@@ -2300,6 +2331,8 @@ bool ImpSvNumberInputScan::ScanEndString( const String& rString,
const String& rDate = pFormatter->GetDateSep();
bDate = SkipString( rDate, rString, nPos); // 10. 10- 10/
}
+ if (bDate && bSignDetectedHere)
+ nSign = 0; // 'D-' takes precedence over signed date
if (bDate
|| ((MayBeIso8601() || MayBeMonthDate())
&& SkipChar( '-', rString, nPos)))
@@ -2866,6 +2899,12 @@ void ImpSvNumberInputScan::ChangeIntl()
cDecSep == pFormatter->GetDateSep().GetChar(0) );
bTextInitialized = false;
aUpperCurrSymbol.Erase();
+ InvalidateDateAcceptancePatterns();
+}
+
+
+void ImpSvNumberInputScan::InvalidateDateAcceptancePatterns()
+{
if (sDateAcceptancePatterns.getLength())
sDateAcceptancePatterns = ::com::sun::star::uno::Sequence< ::rtl::OUString >();
}
diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx
index 2f8d6ffbd1d8..7eb58c8f698f 100644
--- a/svl/source/numbers/zforfind.hxx
+++ b/svl/source/numbers/zforfind.hxx
@@ -74,6 +74,8 @@ public:
*/
bool CanForceToIso8601( DateFormat eDateFormat );
+ void InvalidateDateAcceptancePatterns();
+
private:
SvNumberFormatter* pFormatter;
String* pUpperMonthText; // Array of month names, uppercase
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index c5172a2972b9..e4596551dd44 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -141,19 +141,24 @@ void SvNumberFormatterRegistry_Impl::ConfigurationChanged(
utl::ConfigurationBroadcaster*,
sal_uInt32 nHint)
{
- if ( nHint & SYSLOCALEOPTIONS_HINT_LOCALE )
- {
- ::osl::MutexGuard aGuard( SvNumberFormatter::GetMutex() );
- for( size_t i = 0, n = aFormatters.size(); i < n; ++i )
- aFormatters[ i ]->ReplaceSystemCL( eSysLanguage );
- eSysLanguage = MsLangId::getRealLanguage( LANGUAGE_SYSTEM );
- }
- if ( nHint & SYSLOCALEOPTIONS_HINT_CURRENCY )
- {
- ::osl::MutexGuard aGuard( SvNumberFormatter::GetMutex() );
- for( size_t i = 0, n = aFormatters.size(); i < n; ++i )
- aFormatters[ i ]->ResetDefaultSystemCurrency();
- }
+ ::osl::MutexGuard aGuard( SvNumberFormatter::GetMutex() );
+
+ if ( nHint & SYSLOCALEOPTIONS_HINT_LOCALE )
+ {
+ for( size_t i = 0, n = aFormatters.size(); i < n; ++i )
+ aFormatters[ i ]->ReplaceSystemCL( eSysLanguage );
+ eSysLanguage = MsLangId::getRealLanguage( LANGUAGE_SYSTEM );
+ }
+ if ( nHint & SYSLOCALEOPTIONS_HINT_CURRENCY )
+ {
+ for( size_t i = 0, n = aFormatters.size(); i < n; ++i )
+ aFormatters[ i ]->ResetDefaultSystemCurrency();
+ }
+ if ( nHint & SYSLOCALEOPTIONS_HINT_DATEPATTERNS )
+ {
+ for( size_t i = 0, n = aFormatters.size(); i < n; ++i )
+ aFormatters[ i ]->InvalidateDateAcceptancePatterns();
+ }
}
@@ -3158,6 +3163,12 @@ void SvNumberFormatter::ResetDefaultSystemCurrency()
}
+void SvNumberFormatter::InvalidateDateAcceptancePatterns()
+{
+ pStringScanner->InvalidateDateAcceptancePatterns();
+}
+
+
sal_uInt32 SvNumberFormatter::ImpGetDefaultSystemCurrencyFormat()
{
if ( nDefaultSystemCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND )