diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2014-08-18 20:38:43 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-08-20 03:11:57 -0500 |
commit | ff4d02e35e5187211da457facbb07b8e89c0d556 (patch) | |
tree | fc82551239c745a7acf68d2868d5dbb1746b3369 | |
parent | 6c3327a0644364dab5c7f8b0a49808ac5555b87d (diff) |
fdo#82757 call convertStringToNumber and detectNumberFormat with same locale
So that they agree (among others) on date recognition patterns.
Change-Id: I964142702b5bb23bca2c62433e52f76dfa4bdacb
Reviewed-on: https://gerrit.libreoffice.org/11003
Reviewed-by: David Tardon <dtardon@redhat.com>
Tested-by: David Tardon <dtardon@redhat.com>
-rw-r--r-- | connectivity/source/commontools/DateConversion.cxx | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/connectivity/source/commontools/DateConversion.cxx b/connectivity/source/commontools/DateConversion.cxx index bb44707fa1e3..1f63db832c6c 100644 --- a/connectivity/source/commontools/DateConversion.cxx +++ b/connectivity/source/commontools/DateConversion.cxx @@ -250,7 +250,24 @@ void DBTypeConversion::setValue(const Reference<XColumnUpdate>& xVariant, try { double fValue = xFormatter->convertStringToNumber(nKeyToUse, rString); - sal_Int32 nRealUsedKey = xFormatter->detectNumberFormat(0, rString); + Reference< XNumberFormats > xFormats(xFormatter->getNumberFormatsSupplier()->getNumberFormats()); + Reference< XNumberFormatTypes > xFormatTypes(xFormats, UNO_QUERY); + sal_Int32 nStandardKey(0); + if(xFormatTypes.is()) + { + const Reference< XPropertySet > xFormatProps(xFormats->getByKey(nKeyToUse)); + if (xFormatProps.is()) + { + css::lang::Locale loc; + if (xFormatProps->getPropertyValue("Locale") >>= loc) + nStandardKey = xFormatTypes->getStandardIndex(loc); + } + } + // Why use nStandardKey rather than nKeyToUse here? Don't know, but "it was always like that". + // Previously had hardcoded 0 instead of nStandardKey, which led to problems with dates + // because of differences M/D/Y vs D/M/Y. This at least fixes those problems, but possibly + // nKeyToUse is an even better choice than nStandardKey. + sal_Int32 nRealUsedKey = xFormatter->detectNumberFormat(nStandardKey, rString); if (nRealUsedKey != nKeyToUse) nRealUsedTypeClass = getNumberFormatType(xFormatter, nRealUsedKey) & ~NumberFormat::DEFINED; |